You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

329 lines
8.6 KiB

Add Octicon SVG spritemap (#10107) * Add octicon SVG sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Static prefix Signed-off-by: jolheiser <john.olheiser@gmail.com> * SVG for all repo icons Signed-off-by: jolheiser <john.olheiser@gmail.com> * make vendor Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap out octicons Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move octicons to top of less imports Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix JS Signed-off-by: jolheiser <john.olheiser@gmail.com> * Definitely not a search/replace Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed regex Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move to more generic calls and webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * make svg -> make webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg-sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed a test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg from makefile Signed-off-by: jolheiser <john.olheiser@gmail.com> * Suggestions Signed-off-by: jolheiser <john.olheiser@gmail.com> * Attempt to fix test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert timetracking test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap .octicon for .svg in less Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add aria-hidden Signed-off-by: jolheiser <john.olheiser@gmail.com> * Replace mega-octicon Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix webpack globbing on Windows Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert Co-Authored-By: silverwind <me@silverwind.io> * Fix octions from upstream Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix Vue and missed JS function Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add JS helper and PWA Signed-off-by: jolheiser <john.olheiser@gmail.com> * Preload SVG Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: techknowlogick <matti@mdranta.net>
4 years ago
Add Octicon SVG spritemap (#10107) * Add octicon SVG sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Static prefix Signed-off-by: jolheiser <john.olheiser@gmail.com> * SVG for all repo icons Signed-off-by: jolheiser <john.olheiser@gmail.com> * make vendor Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap out octicons Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move octicons to top of less imports Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix JS Signed-off-by: jolheiser <john.olheiser@gmail.com> * Definitely not a search/replace Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed regex Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move to more generic calls and webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * make svg -> make webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg-sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed a test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg from makefile Signed-off-by: jolheiser <john.olheiser@gmail.com> * Suggestions Signed-off-by: jolheiser <john.olheiser@gmail.com> * Attempt to fix test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert timetracking test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap .octicon for .svg in less Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add aria-hidden Signed-off-by: jolheiser <john.olheiser@gmail.com> * Replace mega-octicon Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix webpack globbing on Windows Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert Co-Authored-By: silverwind <me@silverwind.io> * Fix octions from upstream Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix Vue and missed JS function Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add JS helper and PWA Signed-off-by: jolheiser <john.olheiser@gmail.com> * Preload SVG Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: techknowlogick <matti@mdranta.net>
4 years ago
Add Octicon SVG spritemap (#10107) * Add octicon SVG sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Static prefix Signed-off-by: jolheiser <john.olheiser@gmail.com> * SVG for all repo icons Signed-off-by: jolheiser <john.olheiser@gmail.com> * make vendor Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap out octicons Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move octicons to top of less imports Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix JS Signed-off-by: jolheiser <john.olheiser@gmail.com> * Definitely not a search/replace Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed regex Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move to more generic calls and webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * make svg -> make webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg-sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed a test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg from makefile Signed-off-by: jolheiser <john.olheiser@gmail.com> * Suggestions Signed-off-by: jolheiser <john.olheiser@gmail.com> * Attempt to fix test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert timetracking test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap .octicon for .svg in less Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add aria-hidden Signed-off-by: jolheiser <john.olheiser@gmail.com> * Replace mega-octicon Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix webpack globbing on Windows Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert Co-Authored-By: silverwind <me@silverwind.io> * Fix octions from upstream Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix Vue and missed JS function Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add JS helper and PWA Signed-off-by: jolheiser <john.olheiser@gmail.com> * Preload SVG Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: techknowlogick <matti@mdranta.net>
4 years ago
Add Octicon SVG spritemap (#10107) * Add octicon SVG sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Static prefix Signed-off-by: jolheiser <john.olheiser@gmail.com> * SVG for all repo icons Signed-off-by: jolheiser <john.olheiser@gmail.com> * make vendor Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap out octicons Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move octicons to top of less imports Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix JS Signed-off-by: jolheiser <john.olheiser@gmail.com> * Definitely not a search/replace Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed regex Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move to more generic calls and webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * make svg -> make webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg-sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed a test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg from makefile Signed-off-by: jolheiser <john.olheiser@gmail.com> * Suggestions Signed-off-by: jolheiser <john.olheiser@gmail.com> * Attempt to fix test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert timetracking test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap .octicon for .svg in less Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add aria-hidden Signed-off-by: jolheiser <john.olheiser@gmail.com> * Replace mega-octicon Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix webpack globbing on Windows Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert Co-Authored-By: silverwind <me@silverwind.io> * Fix octions from upstream Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix Vue and missed JS function Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add JS helper and PWA Signed-off-by: jolheiser <john.olheiser@gmail.com> * Preload SVG Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: techknowlogick <matti@mdranta.net>
4 years ago
Add Octicon SVG spritemap (#10107) * Add octicon SVG sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Static prefix Signed-off-by: jolheiser <john.olheiser@gmail.com> * SVG for all repo icons Signed-off-by: jolheiser <john.olheiser@gmail.com> * make vendor Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap out octicons Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move octicons to top of less imports Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix JS Signed-off-by: jolheiser <john.olheiser@gmail.com> * Definitely not a search/replace Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed regex Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move to more generic calls and webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * make svg -> make webpack Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg-sprite Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Missed a test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove svg from makefile Signed-off-by: jolheiser <john.olheiser@gmail.com> * Suggestions Signed-off-by: jolheiser <john.olheiser@gmail.com> * Attempt to fix test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update tests Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert timetracking test Signed-off-by: jolheiser <john.olheiser@gmail.com> * Swap .octicon for .svg in less Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add aria-hidden Signed-off-by: jolheiser <john.olheiser@gmail.com> * Replace mega-octicon Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix webpack globbing on Windows Signed-off-by: jolheiser <john.olheiser@gmail.com> * Revert Co-Authored-By: silverwind <me@silverwind.io> * Fix octions from upstream Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix Vue and missed JS function Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add JS helper and PWA Signed-off-by: jolheiser <john.olheiser@gmail.com> * Preload SVG Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: techknowlogick <matti@mdranta.net>
4 years ago
  1. const fastGlob = require('fast-glob');
  2. const wrapAnsi = require('wrap-ansi');
  3. const CssNanoPlugin = require('cssnano-webpack-plugin');
  4. const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries');
  5. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  6. const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
  7. const PostCSSPresetEnv = require('postcss-preset-env');
  8. const TerserPlugin = require('terser-webpack-plugin');
  9. const VueLoaderPlugin = require('vue-loader/lib/plugin');
  10. const {statSync} = require('fs');
  11. const {resolve, parse} = require('path');
  12. const {LicenseWebpackPlugin} = require('license-webpack-plugin');
  13. const {SourceMapDevToolPlugin} = require('webpack');
  14. const glob = (pattern) => fastGlob.sync(pattern, {cwd: __dirname, absolute: true});
  15. const themes = {};
  16. for (const path of glob('web_src/less/themes/*.less')) {
  17. themes[parse(path).name] = [path];
  18. }
  19. const isProduction = process.env.NODE_ENV !== 'development';
  20. const filterCssImport = (url, ...args) => {
  21. const cssFile = args[1] || args[0]; // resourcePath is 2nd argument for url and 3rd for import
  22. const importedFile = url.replace(/[?#].+/, '').toLowerCase();
  23. if (cssFile.includes('fomantic')) {
  24. if (/brand-icons/.test(importedFile)) return false;
  25. if (/(eot|ttf|otf|woff|svg)$/.test(importedFile)) return false;
  26. }
  27. if (cssFile.includes('font-awesome')) {
  28. if (/(eot|ttf|otf|woff|svg)$/.test(importedFile)) return false;
  29. }
  30. return true;
  31. };
  32. module.exports = {
  33. mode: isProduction ? 'production' : 'development',
  34. entry: {
  35. index: [
  36. resolve(__dirname, 'web_src/js/jquery.js'),
  37. resolve(__dirname, 'web_src/fomantic/build/semantic.js'),
  38. resolve(__dirname, 'web_src/js/index.js'),
  39. resolve(__dirname, 'web_src/fomantic/build/semantic.css'),
  40. resolve(__dirname, 'web_src/less/index.less'),
  41. ],
  42. swagger: [
  43. resolve(__dirname, 'web_src/js/standalone/swagger.js'),
  44. ],
  45. serviceworker: [
  46. resolve(__dirname, 'web_src/js/serviceworker.js'),
  47. ],
  48. 'eventsource.sharedworker': [
  49. resolve(__dirname, 'web_src/js/features/eventsource.sharedworker.js'),
  50. ],
  51. ...themes,
  52. },
  53. devtool: false,
  54. output: {
  55. path: resolve(__dirname, 'public'),
  56. filename: ({chunk}) => {
  57. // serviceworker can only manage assets below it's script's directory so
  58. // we have to put it in / instead of /js/
  59. return chunk.name === 'serviceworker' ? '[name].js' : 'js/[name].js';
  60. },
  61. chunkFilename: 'js/[name].js',
  62. },
  63. optimization: {
  64. minimize: isProduction,
  65. minimizer: [
  66. new TerserPlugin({
  67. sourceMap: true,
  68. extractComments: false,
  69. terserOptions: {
  70. output: {
  71. comments: false,
  72. },
  73. },
  74. }),
  75. new CssNanoPlugin({
  76. sourceMap: true,
  77. cssnanoOptions: {
  78. preset: [
  79. 'default',
  80. {
  81. discardComments: {
  82. removeAll: true,
  83. },
  84. },
  85. ],
  86. },
  87. }),
  88. ],
  89. splitChunks: {
  90. chunks: 'async',
  91. name: (_, chunks) => chunks.map((item) => item.name).join('-'),
  92. cacheGroups: {
  93. // this bundles all monaco's languages into one file instead of emitting 1-65.js files
  94. monaco: {
  95. test: /monaco-editor/,
  96. name: 'monaco',
  97. chunks: 'async',
  98. },
  99. },
  100. },
  101. },
  102. module: {
  103. rules: [
  104. {
  105. test: /\.vue$/,
  106. exclude: /node_modules/,
  107. loader: 'vue-loader',
  108. },
  109. {
  110. test: /\.worker\.js$/,
  111. exclude: /monaco/,
  112. use: [
  113. {
  114. loader: 'worker-loader',
  115. options: {
  116. name: '[name].js',
  117. inline: true,
  118. fallback: false,
  119. },
  120. },
  121. ],
  122. },
  123. {
  124. test: /\.js$/,
  125. exclude: /node_modules/,
  126. use: [
  127. {
  128. loader: 'babel-loader',
  129. options: {
  130. cacheDirectory: true,
  131. cacheCompression: false,
  132. cacheIdentifier: [
  133. resolve(__dirname, 'package.json'),
  134. resolve(__dirname, 'package-lock.json'),
  135. resolve(__dirname, 'webpack.config.js'),
  136. ].map((path) => statSync(path).mtime.getTime()).join(':'),
  137. sourceMaps: true,
  138. presets: [
  139. [
  140. '@babel/preset-env',
  141. {
  142. useBuiltIns: 'usage',
  143. corejs: 3,
  144. },
  145. ],
  146. ],
  147. plugins: [
  148. [
  149. '@babel/plugin-transform-runtime',
  150. {
  151. regenerator: true,
  152. }
  153. ],
  154. '@babel/plugin-proposal-object-rest-spread',
  155. ],
  156. generatorOpts: {
  157. compact: false,
  158. },
  159. },
  160. },
  161. ],
  162. },
  163. {
  164. test: /.css$/i,
  165. use: [
  166. {
  167. loader: MiniCssExtractPlugin.loader,
  168. },
  169. {
  170. loader: 'css-loader',
  171. options: {
  172. importLoaders: 1,
  173. url: filterCssImport,
  174. import: filterCssImport,
  175. sourceMap: true,
  176. },
  177. },
  178. {
  179. loader: 'postcss-loader',
  180. options: {
  181. plugins: () => [
  182. PostCSSPresetEnv(),
  183. ],
  184. sourceMap: true,
  185. },
  186. },
  187. ],
  188. },
  189. {
  190. test: /.less$/i,
  191. use: [
  192. {
  193. loader: MiniCssExtractPlugin.loader,
  194. },
  195. {
  196. loader: 'css-loader',
  197. options: {
  198. importLoaders: 2,
  199. url: filterCssImport,
  200. import: filterCssImport,
  201. sourceMap: true,
  202. },
  203. },
  204. {
  205. loader: 'postcss-loader',
  206. options: {
  207. plugins: () => [
  208. PostCSSPresetEnv(),
  209. ],
  210. sourceMap: true,
  211. },
  212. },
  213. {
  214. loader: 'less-loader',
  215. options: {
  216. sourceMap: true,
  217. },
  218. },
  219. ],
  220. },
  221. {
  222. test: /\.svg$/,
  223. include: resolve(__dirname, 'public/img/svg'),
  224. use: [
  225. {
  226. loader: 'raw-loader',
  227. },
  228. ],
  229. },
  230. {
  231. test: /\.(ttf|woff2?)$/,
  232. use: [
  233. {
  234. loader: 'file-loader',
  235. options: {
  236. name: '[name].[ext]',
  237. outputPath: 'fonts/',
  238. publicPath: (url) => `../fonts/${url}`, // required to remove css/ path segment
  239. },
  240. },
  241. ],
  242. },
  243. {
  244. test: /\.png$/i,
  245. use: [
  246. {
  247. loader: 'file-loader',
  248. options: {
  249. name: '[name].[ext]',
  250. outputPath: 'img/webpack/',
  251. publicPath: (url) => `../img/webpack/${url}`, // required to remove css/ path segment
  252. },
  253. },
  254. ],
  255. },
  256. ],
  257. },
  258. plugins: [
  259. new VueLoaderPlugin(),
  260. // avoid generating useless js output files for css--only chunks
  261. new FixStyleOnlyEntriesPlugin({
  262. extensions: ['less', 'scss', 'css'],
  263. silent: true,
  264. }),
  265. new MiniCssExtractPlugin({
  266. filename: 'css/[name].css',
  267. chunkFilename: 'css/[name].css',
  268. }),
  269. new SourceMapDevToolPlugin({
  270. filename: '[file].map',
  271. include: [
  272. 'js/index.js',
  273. 'css/index.css',
  274. ],
  275. }),
  276. new MonacoWebpackPlugin({
  277. filename: 'js/monaco-[name].worker.js',
  278. }),
  279. new LicenseWebpackPlugin({
  280. outputFilename: 'js/licenses.txt',
  281. perChunkOutput: false,
  282. addBanner: false,
  283. skipChildCompilers: true,
  284. modulesDirectories: [
  285. resolve(__dirname, 'node_modules'),
  286. ],
  287. renderLicenses: (modules) => {
  288. const line = '-'.repeat(80);
  289. return modules.map((module) => {
  290. const {name, version} = module.packageJson;
  291. const {licenseId, licenseText} = module;
  292. const body = wrapAnsi(licenseText || '', 80);
  293. return `${line}\n${name}@${version} - ${licenseId}\n${line}\n${body}`;
  294. }).join('\n');
  295. },
  296. stats: {
  297. warnings: false,
  298. errors: true,
  299. },
  300. }),
  301. ],
  302. performance: {
  303. hints: false,
  304. maxEntrypointSize: Infinity,
  305. maxAssetSize: Infinity,
  306. },
  307. resolve: {
  308. symlinks: false,
  309. alias: {
  310. vue$: 'vue/dist/vue.esm.js', // needed because vue's default export is the runtime only
  311. },
  312. },
  313. watchOptions: {
  314. ignored: [
  315. 'node_modules/**',
  316. ],
  317. },
  318. stats: {
  319. children: false,
  320. },
  321. };