plaid.conf.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const { isProd } = require('@gera2ld/plaid/util');
  2. /**
  3. * For each entry, `key` is the chunk name, `value` has following properties:
  4. * - value.entry: webpack entry.
  5. * - value.html: options object passed to HtmlWebpackPlugin.
  6. * - value.html.inlineSource: if true, JS and CSS files will be inlined in HTML.
  7. */
  8. exports.pages = [
  9. 'background',
  10. 'confirm',
  11. 'options',
  12. 'popup',
  13. ].reduce((res, name) => Object.assign(res, {
  14. [`${name}/index`]: {
  15. entry: `./src/${name}`,
  16. html: options => ({
  17. ...options,
  18. title: 'Violentmonkey',
  19. injectTo: item => ((item.attributes.src || '').endsWith('/index.js') ? 'body' : 'head'),
  20. }),
  21. },
  22. }), {});
  23. const splitVendor = prefix => ({
  24. [prefix]: {
  25. test: new RegExp(`node_modules[/\\\\]${prefix}`),
  26. name: `public/lib/${prefix}`,
  27. chunks: 'all',
  28. priority: 100,
  29. },
  30. });
  31. exports.devServer = false;
  32. exports.devtool = isProd ? false : 'inline-source-map';
  33. exports.optimization = {
  34. runtimeChunk: false,
  35. splitChunks: {
  36. cacheGroups: {
  37. 'common-ui': {
  38. name: 'common-ui',
  39. test: new RegExp([
  40. /\bsvg/,
  41. /src\/common\/(ui|keyboard|load-script-icon)/,
  42. 'node_modules/@violentmonkey/shortcut',
  43. 'node_modules/vue',
  44. ].map(re => re.source || re).join('|').replace(/\\?\//g, '[/\\\\]')),
  45. chunks: 'all',
  46. minChunks: 2,
  47. priority: 100,
  48. },
  49. common: {
  50. name: 'common',
  51. minChunks: 2,
  52. enforce: true,
  53. chunks: 'all',
  54. },
  55. ...splitVendor('codemirror'),
  56. ...splitVendor('tldjs'),
  57. },
  58. },
  59. };
  60. exports.styleOptions = {
  61. /* Files in extensions aren't cached so there's no point in extracting separate css,
  62. * other than minifying, but the gain is negligible. P.S. Extracting+inlining back in html
  63. * doesn't keep the correct order of style elements which breaks appearance when
  64. * using style-ext-html-webpack-plugin or html-inline-css-webpack-plugin. */
  65. extract: false,
  66. };