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.

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