906976957b16e8ca0a659fd3d7310610880da3a22648a70940b6a20aa7efab246e452ebd2b3b29f38c8997c25d218bc4b84a184e0c4351cee2393dd08eae4c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. const ChainedMap = require('./ChainedMap');
  2. const Plugin = require('./Plugin');
  3. module.exports = class extends ChainedMap {
  4. constructor(parent) {
  5. super(parent);
  6. this.minimizers = new ChainedMap(this);
  7. this.extend([
  8. 'concatenateModules',
  9. 'flagIncludedChunks',
  10. 'mergeDuplicateChunks',
  11. 'minimize',
  12. 'namedChunks',
  13. 'namedModules',
  14. 'nodeEnv',
  15. 'noEmitOnErrors',
  16. 'occurrenceOrder',
  17. 'portableRecords',
  18. 'providedExports',
  19. 'removeAvailableModules',
  20. 'removeEmptyChunks',
  21. 'runtimeChunk',
  22. 'sideEffects',
  23. 'splitChunks',
  24. 'usedExports',
  25. ]);
  26. }
  27. minimizer(name) {
  28. if (Array.isArray(name)) {
  29. throw new Error(
  30. 'optimization.minimizer() no longer supports being passed an array. ' +
  31. 'Either switch to the new syntax (https://github.com/neutrinojs/webpack-chain#config-optimization-minimizers-adding) or downgrade to webpack-chain 4. ' +
  32. 'If using Vue this likely means a Vue plugin has not yet been updated to support Vue CLI 4+.',
  33. );
  34. }
  35. return this.minimizers.getOrCompute(
  36. name,
  37. () => new Plugin(this, name, 'optimization.minimizer'),
  38. );
  39. }
  40. toConfig() {
  41. return this.clean(
  42. Object.assign(this.entries() || {}, {
  43. minimizer: this.minimizers.values().map((plugin) => plugin.toConfig()),
  44. }),
  45. );
  46. }
  47. merge(obj, omit = []) {
  48. if (!omit.includes('minimizer') && 'minimizer' in obj) {
  49. Object.keys(obj.minimizer).forEach((name) =>
  50. this.minimizer(name).merge(obj.minimizer[name]),
  51. );
  52. }
  53. return super.merge(obj, [...omit, 'minimizer']);
  54. }
  55. };