plaid.conf.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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: name !== 'background' && (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/(?!zip|tld)',
  42. 'node_modules/@violentmonkey/shortcut',
  43. 'node_modules/@?vue',
  44. ].map(re => re.source || re).join('|').replace(/\\?\//g, '[/\\\\]')),
  45. chunks: c => ![
  46. 'background/index', // only 4kB of common code
  47. 'injected',
  48. 'injected-web',
  49. ].includes(c.name),
  50. },
  51. ...splitVendor('codemirror'),
  52. ...splitVendor('tldjs'),
  53. },
  54. },
  55. };
  56. exports.styleOptions = {
  57. /* Files in extensions aren't cached so there's no point in extracting separate css,
  58. * other than minifying, but the gain is negligible. P.S. Extracting+inlining back in html
  59. * doesn't keep the correct order of style elements which breaks appearance when
  60. * using style-ext-html-webpack-plugin or html-inline-css-webpack-plugin. */
  61. extract: false,
  62. };