plaid.conf.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. const injectTo = item => {
  9. if (!(item.attributes.src || '').endsWith('/index.js')) return 'head';
  10. };
  11. const htmlFactory = extra => options => ({
  12. ...options,
  13. title: 'Violentmonkey',
  14. ...extra,
  15. chunks: ['browser', ...options.chunks],
  16. injectTo,
  17. });
  18. exports.pages = {
  19. 'browser': {
  20. entry: './src/common/browser',
  21. },
  22. 'background/index': {
  23. entry: './src/background',
  24. html: htmlFactory(),
  25. },
  26. 'options/index': {
  27. entry: './src/options',
  28. html: htmlFactory(),
  29. },
  30. 'confirm/index': {
  31. entry: './src/confirm',
  32. html: htmlFactory(),
  33. },
  34. 'popup/index': {
  35. entry: './src/popup',
  36. html: htmlFactory(),
  37. },
  38. injected: {
  39. entry: './src/injected',
  40. },
  41. };
  42. const splitVendor = name => ({
  43. [name]: {
  44. test: new RegExp(`node_modules[/\\\\]${name}`),
  45. name: `public/lib/${name}`,
  46. chunks: 'all',
  47. priority: 100,
  48. },
  49. });
  50. exports.devServer = false;
  51. exports.devtool = isProd ? false : 'inline-source-map';
  52. exports.optimization = {
  53. runtimeChunk: false,
  54. splitChunks: {
  55. cacheGroups: {
  56. common: {
  57. name: 'common',
  58. minChunks: 2,
  59. enforce: true,
  60. chunks(chunk) {
  61. return ![
  62. 'browser',
  63. 'injected',
  64. ].includes(chunk.name);
  65. },
  66. },
  67. ...splitVendor('codemirror'),
  68. ...splitVendor('tldjs'),
  69. ...splitVendor('vue'),
  70. },
  71. },
  72. };