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.

345 lines
9.3 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 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. resolve(__dirname, 'web_src/less/standalone/swagger.less'),
  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. sourceMaps: true,
  122. cacheDirectory: true,
  123. cacheCompression: false,
  124. cacheIdentifier: [
  125. resolve(__dirname, 'package.json'),
  126. resolve(__dirname, 'package-lock.json'),
  127. resolve(__dirname, 'webpack.config.js'),
  128. ].map((path) => statSync(path).mtime.getTime()).join(':'),
  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. sourceMap: true,
  163. importLoaders: 1,
  164. url: filterCssImport,
  165. import: filterCssImport,
  166. },
  167. },
  168. {
  169. loader: 'postcss-loader',
  170. options: {
  171. sourceMap: true,
  172. postcssOptions: {
  173. plugins: [
  174. [
  175. 'postcss-preset-env',
  176. {
  177. features: {
  178. 'system-ui-font-family': false,
  179. },
  180. },
  181. ],
  182. ],
  183. },
  184. },
  185. },
  186. ],
  187. },
  188. {
  189. test: /.less$/i,
  190. use: [
  191. {
  192. loader: MiniCssExtractPlugin.loader,
  193. },
  194. {
  195. loader: 'css-loader',
  196. options: {
  197. sourceMap: true,
  198. importLoaders: 2,
  199. url: filterCssImport,
  200. import: filterCssImport,
  201. },
  202. },
  203. {
  204. loader: 'postcss-loader',
  205. options: {
  206. sourceMap: true,
  207. postcssOptions: {
  208. plugins: [
  209. [
  210. 'postcss-preset-env',
  211. {
  212. features: {
  213. 'system-ui-font-family': false,
  214. },
  215. },
  216. ],
  217. ],
  218. },
  219. },
  220. },
  221. {
  222. loader: 'less-loader',
  223. options: {
  224. sourceMap: true,
  225. },
  226. },
  227. ],
  228. },
  229. {
  230. test: /\.svg$/,
  231. include: resolve(__dirname, 'public/img/svg'),
  232. use: [
  233. {
  234. loader: 'raw-loader',
  235. },
  236. ],
  237. },
  238. {
  239. test: /\.(ttf|woff2?)$/,
  240. use: [
  241. {
  242. loader: 'file-loader',
  243. options: {
  244. name: '[name].[ext]',
  245. outputPath: 'fonts/',
  246. publicPath: (url) => `../fonts/${url}`, // required to remove css/ path segment
  247. },
  248. },
  249. ],
  250. },
  251. {
  252. test: /\.png$/i,
  253. use: [
  254. {
  255. loader: 'file-loader',
  256. options: {
  257. name: '[name].[ext]',
  258. outputPath: 'img/webpack/',
  259. publicPath: (url) => `../img/webpack/${url}`, // required to remove css/ path segment
  260. },
  261. },
  262. ],
  263. },
  264. ],
  265. },
  266. plugins: [
  267. new VueLoaderPlugin(),
  268. // avoid generating useless js output files for css--only chunks
  269. new FixStyleOnlyEntriesPlugin({
  270. extensions: ['less', 'scss', 'css'],
  271. silent: true,
  272. }),
  273. new MiniCssExtractPlugin({
  274. filename: 'css/[name].css',
  275. chunkFilename: 'css/[name].css',
  276. }),
  277. new SourceMapDevToolPlugin({
  278. filename: '[file].map',
  279. include: [
  280. 'js/index.js',
  281. 'css/index.css',
  282. ],
  283. }),
  284. new MonacoWebpackPlugin({
  285. filename: 'js/monaco-[name].worker.js',
  286. }),
  287. isProduction ? new LicenseWebpackPlugin({
  288. outputFilename: 'js/licenses.txt',
  289. perChunkOutput: false,
  290. addBanner: false,
  291. skipChildCompilers: true,
  292. modulesDirectories: [
  293. resolve(__dirname, 'node_modules'),
  294. ],
  295. additionalModules: [
  296. '@primer/octicons',
  297. ].map((name) => ({name, directory: resolve(__dirname, `node_modules/${name}`)})),
  298. renderLicenses: (modules) => {
  299. const line = '-'.repeat(80);
  300. return modules.map((module) => {
  301. const {name, version} = module.packageJson;
  302. const {licenseId, licenseText} = module;
  303. const body = wrapAnsi(licenseText || '', 80);
  304. return `${line}\n${name}@${version} - ${licenseId}\n${line}\n${body}`;
  305. }).join('\n');
  306. },
  307. stats: {
  308. warnings: false,
  309. errors: true,
  310. },
  311. }) : new AddAssetPlugin('js/licenses.txt', `Licenses are disabled during development`),
  312. ],
  313. performance: {
  314. hints: false,
  315. maxEntrypointSize: Infinity,
  316. maxAssetSize: Infinity,
  317. },
  318. resolve: {
  319. symlinks: false,
  320. alias: {
  321. vue$: 'vue/dist/vue.esm.js', // needed because vue's default export is the runtime only
  322. },
  323. },
  324. watchOptions: {
  325. ignored: [
  326. 'node_modules/**',
  327. ],
  328. },
  329. stats: {
  330. children: false,
  331. excludeAssets: [
  332. // exclude monaco's language chunks in stats output for brevity
  333. // https://github.com/microsoft/monaco-editor-webpack-plugin/issues/113
  334. /^js\/[0-9]+\.js$/,
  335. ],
  336. },
  337. };