plaid.conf.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. };