plaid.conf.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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: 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\/(ui|keyboard|load-script-icon)/,
  46. 'node_modules/@violentmonkey/shortcut',
  47. 'node_modules/vue',
  48. ].map(re => re.source || re).join('|').replace(/\\?\//g, '[/\\\\]')),
  49. chunks: 'all',
  50. minChunks: 2,
  51. priority: 100,
  52. },
  53. common: {
  54. name: 'common',
  55. minChunks: 2,
  56. enforce: true,
  57. chunks: 'all',
  58. },
  59. ...splitVendor('codemirror'),
  60. ...splitVendor('tldjs'),
  61. },
  62. },
  63. };
  64. exports.styleOptions = {
  65. /* Files in extensions aren't cached so there's no point in extracting separate css,
  66. * other than minifying, but the gain is negligible. P.S. Extracting+inlining back in html
  67. * doesn't keep the correct order of style elements which breaks appearance when
  68. * using style-ext-html-webpack-plugin or html-inline-css-webpack-plugin. */
  69. extract: false,
  70. };