plaid.conf.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. const { isProd } = require('@gera2ld/plaid/util');
  2. const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
  3. /**
  4. * For each entry, `key` is the chunk name, `value` has following properties:
  5. * - value.entry: webpack entry.
  6. * - value.html: options object passed to HtmlWebpackPlugin.
  7. * - value.html.inlineSource: if true, JS and CSS files will be inlined in HTML.
  8. */
  9. exports.pages = [
  10. 'background',
  11. 'confirm',
  12. 'options',
  13. 'popup',
  14. ].reduce((res, name) => Object.assign(res, {
  15. [`${name}/index`]: {
  16. entry: `./src/${name}`,
  17. html: options => ({
  18. ...options,
  19. title: 'Violentmonkey',
  20. injectTo: item => ((item.attributes.src || '').endsWith('/index.js') ? 'body' : 'head'),
  21. }),
  22. },
  23. }), {});
  24. const splitVendor = prefix => ({
  25. [prefix]: {
  26. test: new RegExp(`node_modules[/\\\\]${prefix}`),
  27. name: `public/lib/${prefix}`,
  28. chunks: 'all',
  29. priority: 100,
  30. },
  31. });
  32. exports.devServer = false;
  33. exports.devtool = isProd ? false : 'inline-source-map';
  34. exports.optimization = {
  35. runtimeChunk: false,
  36. splitChunks: {
  37. cacheGroups: {
  38. 'common-ui': {
  39. name: 'common-ui',
  40. test: new RegExp([
  41. /\bsvg/,
  42. /src\/common\/(ui|keyboard|load-script-icon)/,
  43. 'node_modules/@violentmonkey/shortcut',
  44. 'node_modules/vue',
  45. ].map(re => re.source || re).join('|').replace(/\\?\//g, '[/\\\\]')),
  46. chunks: 'all',
  47. minChunks: 2,
  48. priority: 100,
  49. },
  50. common: {
  51. name: 'common',
  52. minChunks: 2,
  53. enforce: true,
  54. chunks: 'all',
  55. },
  56. ...splitVendor('codemirror'),
  57. ...splitVendor('tldjs'),
  58. },
  59. },
  60. minimizer: isProd && [
  61. /* Combining @media (prefers-color-scheme: dark) into one query.
  62. * WARNING! html-inline-css-webpack-plugin doesn't detect CSS from mini-css-extract-plugin
  63. * in `watch` build so it's only enabled in prod. If we see a difference between the two,
  64. * we should remove this plugin or fix the above-mentioned problem. */
  65. new OptimizeCssAssetsPlugin({
  66. cssProcessor: require('postcss')([
  67. require('postcss-combine-media-query'),
  68. require('cssnano'),
  69. ]),
  70. }),
  71. ],
  72. };