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.

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