plaid.conf.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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}.*?\\.js`),
  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: {
  38. name: 'common',
  39. minChunks: 2,
  40. enforce: true,
  41. chunks: 'all',
  42. },
  43. ...splitVendor('codemirror'),
  44. ...splitVendor('tldjs'),
  45. ...splitVendor('vue'),
  46. },
  47. },
  48. };