plaid.conf.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const path = require('path');
  2. const { defaultOptions, isProd } = require('@gera2ld/plaid/util');
  3. defaultOptions.alias = {
  4. '@': path.resolve('src'),
  5. };
  6. /**
  7. * For each entry, `key` is the chunk name, `value` has following properties:
  8. * - value.entry: webpack entry.
  9. * - value.html: options object passed to HtmlWebpackPlugin.
  10. * - value.html.inlineSource: if true, JS and CSS files will be inlined in HTML.
  11. */
  12. exports.pages = [
  13. 'background',
  14. 'confirm',
  15. 'options',
  16. 'popup',
  17. ].reduce((res, name) => Object.assign(res, {
  18. [`${name}/index`]: {
  19. entry: `./src/${name}`,
  20. html: name !== 'background' && (options => ({
  21. ...options,
  22. title: 'Violentmonkey',
  23. injectTo: item => ((item.attributes.src || '').endsWith('/index.js') ? 'body' : 'head'),
  24. })),
  25. },
  26. }), {});
  27. const splitVendor = prefix => ({
  28. [prefix]: {
  29. test: new RegExp(`node_modules[/\\\\]${prefix}`),
  30. name: `public/lib/${prefix}`,
  31. chunks: 'all',
  32. priority: 100,
  33. },
  34. });
  35. exports.devServer = false;
  36. exports.devtool = isProd ? false : 'inline-source-map';
  37. exports.optimization = {
  38. runtimeChunk: false,
  39. splitChunks: {
  40. cacheGroups: {
  41. 'common-ui': {
  42. name: 'common-ui',
  43. test: new RegExp([
  44. /\bsvg/,
  45. 'src/common/(?!zip|tld)',
  46. 'node_modules/@violentmonkey/shortcut',
  47. 'node_modules/@?vue',
  48. ].map(re => re.source || re).join('|').replace(/\\?\//g, '[/\\\\]')),
  49. chunks: c => ![
  50. 'background/index', // only 4kB of common code
  51. 'injected',
  52. 'injected-web',
  53. ].includes(c.name),
  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. };