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.

323 lines
8.5 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 CssMinimizerPlugin = require('css-minimizer-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 CssMinimizerPlugin({
  76. sourceMap: true,
  77. minimizerOptions: {
  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. },
  93. },
  94. module: {
  95. rules: [
  96. {
  97. test: /\.vue$/,
  98. exclude: /node_modules/,
  99. loader: 'vue-loader',
  100. },
  101. {
  102. test: /\.worker\.js$/,
  103. exclude: /monaco/,
  104. use: [
  105. {
  106. loader: 'worker-loader',
  107. options: {
  108. inline: 'no-fallback',
  109. },
  110. },
  111. ],
  112. },
  113. {
  114. test: /\.js$/,
  115. exclude: /node_modules/,
  116. use: [
  117. {
  118. loader: 'babel-loader',
  119. options: {
  120. cacheDirectory: true,
  121. cacheCompression: false,
  122. cacheIdentifier: [
  123. resolve(__dirname, 'package.json'),
  124. resolve(__dirname, 'package-lock.json'),
  125. resolve(__dirname, 'webpack.config.js'),
  126. ].map((path) => statSync(path).mtime.getTime()).join(':'),
  127. sourceMaps: true,
  128. presets: [
  129. [
  130. '@babel/preset-env',
  131. {
  132. useBuiltIns: 'usage',
  133. corejs: 3,
  134. },
  135. ],
  136. ],
  137. plugins: [
  138. [
  139. '@babel/plugin-transform-runtime',
  140. {
  141. regenerator: true,
  142. }
  143. ],
  144. ],
  145. generatorOpts: {
  146. compact: false,
  147. },
  148. },
  149. },
  150. ],
  151. },
  152. {
  153. test: /.css$/i,
  154. use: [
  155. {
  156. loader: MiniCssExtractPlugin.loader,
  157. },
  158. {
  159. loader: 'css-loader',
  160. options: {
  161. importLoaders: 1,
  162. url: filterCssImport,
  163. import: filterCssImport,
  164. sourceMap: true,
  165. },
  166. },
  167. {
  168. loader: 'postcss-loader',
  169. options: {
  170. plugins: () => [
  171. PostCSSPresetEnv(),
  172. ],
  173. sourceMap: true,
  174. },
  175. },
  176. ],
  177. },
  178. {
  179. test: /.less$/i,
  180. use: [
  181. {
  182. loader: MiniCssExtractPlugin.loader,
  183. },
  184. {
  185. loader: 'css-loader',
  186. options: {
  187. importLoaders: 2,
  188. url: filterCssImport,
  189. import: filterCssImport,
  190. sourceMap: true,
  191. },
  192. },
  193. {
  194. loader: 'postcss-loader',
  195. options: {
  196. plugins: () => [
  197. PostCSSPresetEnv(),
  198. ],
  199. sourceMap: true,
  200. },
  201. },
  202. {
  203. loader: 'less-loader',
  204. options: {
  205. sourceMap: true,
  206. },
  207. },
  208. ],
  209. },
  210. {
  211. test: /\.svg$/,
  212. include: resolve(__dirname, 'public/img/svg'),
  213. use: [
  214. {
  215. loader: 'raw-loader',
  216. },
  217. ],
  218. },
  219. {
  220. test: /\.(ttf|woff2?)$/,
  221. use: [
  222. {
  223. loader: 'file-loader',
  224. options: {
  225. name: '[name].[ext]',
  226. outputPath: 'fonts/',
  227. publicPath: (url) => `../fonts/${url}`, // required to remove css/ path segment
  228. },
  229. },
  230. ],
  231. },
  232. {
  233. test: /\.png$/i,
  234. use: [
  235. {
  236. loader: 'file-loader',
  237. options: {
  238. name: '[name].[ext]',
  239. outputPath: 'img/webpack/',
  240. publicPath: (url) => `../img/webpack/${url}`, // required to remove css/ path segment
  241. },
  242. },
  243. ],
  244. },
  245. ],
  246. },
  247. plugins: [
  248. new VueLoaderPlugin(),
  249. // avoid generating useless js output files for css--only chunks
  250. new FixStyleOnlyEntriesPlugin({
  251. extensions: ['less', 'scss', 'css'],
  252. silent: true,
  253. }),
  254. new MiniCssExtractPlugin({
  255. filename: 'css/[name].css',
  256. chunkFilename: 'css/[name].css',
  257. }),
  258. new SourceMapDevToolPlugin({
  259. filename: '[file].map',
  260. include: [
  261. 'js/index.js',
  262. 'css/index.css',
  263. ],
  264. }),
  265. new MonacoWebpackPlugin({
  266. filename: 'js/monaco-[name].worker.js',
  267. }),
  268. new LicenseWebpackPlugin({
  269. outputFilename: 'js/licenses.txt',
  270. perChunkOutput: false,
  271. addBanner: false,
  272. skipChildCompilers: true,
  273. modulesDirectories: [
  274. resolve(__dirname, 'node_modules'),
  275. ],
  276. renderLicenses: (modules) => {
  277. const line = '-'.repeat(80);
  278. return modules.map((module) => {
  279. const {name, version} = module.packageJson;
  280. const {licenseId, licenseText} = module;
  281. const body = wrapAnsi(licenseText || '', 80);
  282. return `${line}\n${name}@${version} - ${licenseId}\n${line}\n${body}`;
  283. }).join('\n');
  284. },
  285. stats: {
  286. warnings: false,
  287. errors: true,
  288. },
  289. }),
  290. ],
  291. performance: {
  292. hints: false,
  293. maxEntrypointSize: Infinity,
  294. maxAssetSize: Infinity,
  295. },
  296. resolve: {
  297. symlinks: false,
  298. alias: {
  299. vue$: 'vue/dist/vue.esm.js', // needed because vue's default export is the runtime only
  300. },
  301. },
  302. watchOptions: {
  303. ignored: [
  304. 'node_modules/**',
  305. ],
  306. },
  307. stats: {
  308. children: false,
  309. excludeAssets: [
  310. // exclude monaco's language chunks in stats output for brevity
  311. // https://github.com/microsoft/monaco-editor-webpack-plugin/issues/113
  312. /^js\/[0-9]+\.js$/,
  313. ],
  314. },
  315. };