plaid.conf.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. scriptLoading: 'blocking', // we don't need `defer` and it breaks in some browsers, see #1632
  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. // don't extract CSS as it'll change the relative order of rules which breaks appearance
  43. 'src/common/(?!zip|.*\\.css$)',
  44. 'node_modules/@violentmonkey/shortcut',
  45. 'node_modules/@?vue',
  46. ].map(re => re.source || re).join('|').replace(/\\?\//g, '[/\\\\]')),
  47. chunks: c => ![
  48. 'background/index', // only 4kB of common code
  49. 'injected',
  50. 'injected-web',
  51. ].includes(c.name),
  52. },
  53. ...splitVendor('codemirror'),
  54. },
  55. },
  56. };