plaid.conf.js 2.9 KB

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