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.

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