plaid.conf.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. };
  39. const splitVendor = prefix => ({
  40. [prefix]: {
  41. test: new RegExp(`node_modules[/\\\\]${prefix}.*?\\.js`),
  42. name: `public/lib/${prefix}`,
  43. chunks: 'all',
  44. priority: 100,
  45. },
  46. });
  47. exports.devServer = false;
  48. exports.devtool = isProd ? false : 'inline-source-map';
  49. exports.optimization = {
  50. runtimeChunk: false,
  51. splitChunks: {
  52. cacheGroups: {
  53. common: {
  54. name: 'common',
  55. minChunks: 2,
  56. enforce: true,
  57. chunks: chunk => chunk.name !== 'browser',
  58. },
  59. ...splitVendor('codemirror'),
  60. ...splitVendor('tldjs'),
  61. ...splitVendor('vue'),
  62. },
  63. },
  64. };