@rushstack/webpack4-module-minifier-plugin 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +61 -0
  3. package/dist/tsdoc-metadata.json +11 -0
  4. package/dist/webpack4-module-minifier-plugin.d.ts +346 -0
  5. package/lib/AsyncImportCompressionPlugin.d.ts +14 -0
  6. package/lib/AsyncImportCompressionPlugin.d.ts.map +1 -0
  7. package/lib/AsyncImportCompressionPlugin.js +200 -0
  8. package/lib/AsyncImportCompressionPlugin.js.map +1 -0
  9. package/lib/Constants.d.ts +28 -0
  10. package/lib/Constants.d.ts.map +1 -0
  11. package/lib/Constants.js +33 -0
  12. package/lib/Constants.js.map +1 -0
  13. package/lib/GenerateLicenseFileForAsset.d.ts +13 -0
  14. package/lib/GenerateLicenseFileForAsset.d.ts.map +1 -0
  15. package/lib/GenerateLicenseFileForAsset.js +79 -0
  16. package/lib/GenerateLicenseFileForAsset.js.map +1 -0
  17. package/lib/ModuleMinifierPlugin.d.ts +18 -0
  18. package/lib/ModuleMinifierPlugin.d.ts.map +1 -0
  19. package/lib/ModuleMinifierPlugin.js +439 -0
  20. package/lib/ModuleMinifierPlugin.js.map +1 -0
  21. package/lib/ModuleMinifierPlugin.types.d.ts +217 -0
  22. package/lib/ModuleMinifierPlugin.types.d.ts.map +1 -0
  23. package/lib/ModuleMinifierPlugin.types.js +5 -0
  24. package/lib/ModuleMinifierPlugin.types.js.map +1 -0
  25. package/lib/OverrideWebpackIdentifierAllocation.d.ts +2 -0
  26. package/lib/OverrideWebpackIdentifierAllocation.d.ts.map +1 -0
  27. package/lib/OverrideWebpackIdentifierAllocation.js +9 -0
  28. package/lib/OverrideWebpackIdentifierAllocation.js.map +1 -0
  29. package/lib/ParallelCompiler.d.ts +11 -0
  30. package/lib/ParallelCompiler.d.ts.map +1 -0
  31. package/lib/ParallelCompiler.js +90 -0
  32. package/lib/ParallelCompiler.js.map +1 -0
  33. package/lib/PortableMinifierIdsPlugin.d.ts +13 -0
  34. package/lib/PortableMinifierIdsPlugin.d.ts.map +1 -0
  35. package/lib/PortableMinifierIdsPlugin.js +129 -0
  36. package/lib/PortableMinifierIdsPlugin.js.map +1 -0
  37. package/lib/RehydrateAsset.d.ts +11 -0
  38. package/lib/RehydrateAsset.d.ts.map +1 -0
  39. package/lib/RehydrateAsset.js +143 -0
  40. package/lib/RehydrateAsset.js.map +1 -0
  41. package/lib/index.d.ts +9 -0
  42. package/lib/index.d.ts.map +1 -0
  43. package/lib/index.js +32 -0
  44. package/lib/index.js.map +1 -0
  45. package/lib/workerPool/WebpackWorker.d.ts +2 -0
  46. package/lib/workerPool/WebpackWorker.d.ts.map +1 -0
  47. package/lib/workerPool/WebpackWorker.js +101 -0
  48. package/lib/workerPool/WebpackWorker.js.map +1 -0
  49. package/package.json +56 -0
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.rehydrateAsset = void 0;
6
+ const webpack_sources_1 = require("webpack-sources");
7
+ const Constants_1 = require("./Constants");
8
+ /**
9
+ * Rehydrates an asset with minified modules.
10
+ * @param asset - The asset
11
+ * @param moduleMap - The minified modules
12
+ * @param banner - A banner to inject for license information
13
+ * @public
14
+ */
15
+ function rehydrateAsset(asset, moduleMap, banner) {
16
+ const { source: assetSource, modules } = asset;
17
+ const assetCode = assetSource.source();
18
+ const tokenIndex = assetCode.indexOf(Constants_1.CHUNK_MODULES_TOKEN);
19
+ if (tokenIndex < 0) {
20
+ // This is not a JS asset.
21
+ return handleExternals(assetSource, asset);
22
+ }
23
+ const suffixStart = tokenIndex + Constants_1.CHUNK_MODULES_TOKEN.length;
24
+ const suffix = assetCode.slice(suffixStart);
25
+ const prefix = new webpack_sources_1.ReplaceSource(assetSource);
26
+ // Preserve source map via fiddly logic
27
+ prefix.replace(tokenIndex, assetCode.length, '');
28
+ if (!modules.length) {
29
+ // Empty chunk, degenerate case
30
+ return new webpack_sources_1.ConcatSource(banner, prefix, '[]', suffix);
31
+ }
32
+ const emptyFunction = 'function(){}'; // eslint-disable-line @typescript-eslint/typedef
33
+ // This must not have the global flag set
34
+ const validIdRegex = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
35
+ const source = new webpack_sources_1.ConcatSource(banner, prefix);
36
+ const firstModuleId = modules[0];
37
+ const lastModuleId = modules[modules.length - 1];
38
+ // Extended logic from webpack.Template.getModulesArrayBounds
39
+ const minId = typeof firstModuleId === 'number' ? firstModuleId : 0;
40
+ const maxId = typeof lastModuleId === 'number' ? lastModuleId : Infinity;
41
+ const simpleArrayOverhead = 2 + maxId;
42
+ let concatArrayOverhead = simpleArrayOverhead + 9;
43
+ let useObject = typeof firstModuleId !== 'number' || typeof lastModuleId !== 'number';
44
+ let objectOverhead = 1;
45
+ let lastId = 0;
46
+ if (!useObject) {
47
+ for (const id of modules) {
48
+ if (typeof id !== 'number') {
49
+ // This must be an object
50
+ useObject = true;
51
+ break;
52
+ }
53
+ // This is the extension from webpack.Template.getModulesArrayBounds
54
+ // We can make smaller emit by injecting additional filler arrays
55
+ const delta = id - lastId - 1;
56
+ // Compare the length of `],Array(${delta}),[` to ','.repeat(delta + 1)
57
+ const threshold = (lastId === 0 ? 7 : 11) + ('' + delta).length;
58
+ const fillerArraySavings = delta + 1 - threshold;
59
+ if (fillerArraySavings > 0) {
60
+ concatArrayOverhead -= fillerArraySavings;
61
+ }
62
+ objectOverhead += 2 + ('' + id).length;
63
+ lastId = id;
64
+ }
65
+ }
66
+ const useConcat = concatArrayOverhead < simpleArrayOverhead;
67
+ const arrayOverhead = useConcat ? concatArrayOverhead : simpleArrayOverhead;
68
+ useObject = useObject || objectOverhead < arrayOverhead;
69
+ if (useObject) {
70
+ // Write an object literal
71
+ let separator = '{';
72
+ for (const id of modules) {
73
+ // If the id is legal to use as a key in a JavaScript object literal, use as-is
74
+ const javascriptId = typeof id !== 'string' || validIdRegex.test(id) ? id : JSON.stringify(id);
75
+ source.add(`${separator}${javascriptId}:`);
76
+ separator = ',';
77
+ const item = moduleMap.get(id);
78
+ const moduleCode = item ? item.source : emptyFunction;
79
+ source.add(moduleCode);
80
+ }
81
+ source.add('}');
82
+ }
83
+ else {
84
+ // Write one or more array literals, joined by Array(gap) expressions
85
+ // There will never be more than 16 + ("" + minId).length consecutive commas, so 40 is more than will ever be used
86
+ // This is because the above criteria triggers an Array(len) expression instead
87
+ const enoughCommas = ',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,';
88
+ const useConcatAtStart = useConcat && minId > 8;
89
+ lastId = useConcatAtStart ? minId : 0;
90
+ // TODO: Just because we want to use concat elsewhere doesn't mean its optimal to use at the start
91
+ let separator = useConcatAtStart ? `Array(${minId}).concat([` : '[';
92
+ let concatInserted = useConcatAtStart;
93
+ for (const id of modules) {
94
+ const delta = id - lastId - 1;
95
+ const deltaStr = '' + delta;
96
+ const fillerArrayThreshold = 11 + deltaStr.length;
97
+ const item = moduleMap.get(id);
98
+ const moduleCode = item ? item.source : emptyFunction;
99
+ if (useConcat && delta + 1 > fillerArrayThreshold) {
100
+ if (concatInserted) {
101
+ source.add(`],Array(${deltaStr}),[`);
102
+ }
103
+ else {
104
+ source.add(`].concat(Array(${deltaStr}),[`);
105
+ concatInserted = true;
106
+ }
107
+ }
108
+ else {
109
+ source.add(separator + enoughCommas.slice(0, delta + 1));
110
+ }
111
+ lastId = id;
112
+ source.add(moduleCode);
113
+ separator = '';
114
+ }
115
+ source.add(useConcat ? '])' : ']');
116
+ }
117
+ source.add(suffix);
118
+ return handleExternals(new webpack_sources_1.CachedSource(source), asset);
119
+ }
120
+ exports.rehydrateAsset = rehydrateAsset;
121
+ function handleExternals(source, asset) {
122
+ const { externalNames } = asset;
123
+ if (externalNames.size) {
124
+ const replaceSource = new webpack_sources_1.ReplaceSource(source);
125
+ const code = source.source();
126
+ const externalIdRegex = /__WEBPACK_EXTERNAL_MODULE_[A-Za-z0-9_$]+/g;
127
+ // RegExp.exec uses null or an array as the return type, explicitly
128
+ let match = null;
129
+ while ((match = externalIdRegex.exec(code))) {
130
+ const id = match[0];
131
+ const mapped = externalNames.get(id);
132
+ if (mapped === undefined) {
133
+ console.error(`Missing minified external for ${id} in ${asset.fileName}!`);
134
+ }
135
+ else {
136
+ replaceSource.replace(match.index, externalIdRegex.lastIndex - 1, mapped);
137
+ }
138
+ }
139
+ return new webpack_sources_1.CachedSource(replaceSource);
140
+ }
141
+ return source;
142
+ }
143
+ //# sourceMappingURL=RehydrateAsset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RehydrateAsset.js","sourceRoot":"","sources":["../src/RehydrateAsset.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,qDAAoF;AAEpF,2CAAkD;AAGlD;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,KAAiB,EAAE,SAAqB,EAAE,MAAc;IACrF,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAE/C,MAAM,SAAS,GAAW,WAAW,CAAC,MAAM,EAAY,CAAC;IAEzD,MAAM,UAAU,GAAW,SAAS,CAAC,OAAO,CAAC,+BAAmB,CAAC,CAAC;IAClE,IAAI,UAAU,GAAG,CAAC,EAAE;QAClB,0BAA0B;QAC1B,OAAO,eAAe,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;KAC5C;IACD,MAAM,WAAW,GAAW,UAAU,GAAG,+BAAmB,CAAC,MAAM,CAAC;IACpE,MAAM,MAAM,GAAW,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAEpD,MAAM,MAAM,GAAkB,IAAI,+BAAa,CAAC,WAAW,CAAC,CAAC;IAC7D,uCAAuC;IACvC,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,CAAC,MAA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,8BAAY,CAAC,aAAa,CAAC,CAAC;KACxC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { CachedSource, ConcatSource, ReplaceSource, Source } from 'webpack-sources';\n\nimport { CHUNK_MODULES_TOKEN } from './Constants';\nimport { IAssetInfo, IModuleMap, IModuleInfo } from './ModuleMinifierPlugin.types';\n\n/**\n * Rehydrates an asset with minified modules.\n * @param asset - The asset\n * @param moduleMap - The minified modules\n * @param banner - A banner to inject for license information\n * @public\n */\nexport function rehydrateAsset(asset: IAssetInfo, moduleMap: IModuleMap, banner: string): Source {\n const { source: assetSource, modules } = asset;\n\n const assetCode: string = assetSource.source() as string;\n\n const tokenIndex: number = assetCode.indexOf(CHUNK_MODULES_TOKEN);\n if (tokenIndex < 0) {\n // This is not a JS asset.\n return handleExternals(assetSource, asset);\n }\n const suffixStart: number = tokenIndex + CHUNK_MODULES_TOKEN.length;\n const suffix: string = assetCode.slice(suffixStart);\n\n const prefix: ReplaceSource = new ReplaceSource(assetSource);\n // Preserve source map via fiddly logic\n prefix.replace(tokenIndex, assetCode.length, '');\n\n if (!modules.length) {\n // Empty chunk, degenerate case\n return new ConcatSource(banner, prefix, '[]', suffix);\n }\n\n const emptyFunction = 'function(){}'; // eslint-disable-line @typescript-eslint/typedef\n // This must not have the global flag set\n const validIdRegex: RegExp = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\n\n const source: ConcatSource = new ConcatSource(banner, prefix);\n\n const firstModuleId: string | number = modules[0];\n const lastModuleId: string | number = modules[modules.length - 1];\n\n // Extended logic from webpack.Template.getModulesArrayBounds\n const minId: number = typeof firstModuleId === 'number' ? firstModuleId : 0;\n const maxId: number = typeof lastModuleId === 'number' ? lastModuleId : Infinity;\n\n const simpleArrayOverhead: number = 2 + maxId;\n let concatArrayOverhead: number = simpleArrayOverhead + 9;\n\n let useObject: boolean = typeof firstModuleId !== 'number' || typeof lastModuleId !== 'number';\n let objectOverhead: number = 1;\n let lastId: number = 0;\n\n if (!useObject) {\n for (const id of modules) {\n if (typeof id !== 'number') {\n // This must be an object\n useObject = true;\n break;\n }\n\n // This is the extension from webpack.Template.getModulesArrayBounds\n // We can make smaller emit by injecting additional filler arrays\n const delta: number = id - lastId - 1;\n\n // Compare the length of `],Array(${delta}),[` to ','.repeat(delta + 1)\n const threshold: number = (lastId === 0 ? 7 : 11) + ('' + delta).length;\n const fillerArraySavings: number = delta + 1 - threshold;\n if (fillerArraySavings > 0) {\n concatArrayOverhead -= fillerArraySavings;\n }\n\n objectOverhead += 2 + ('' + id).length;\n lastId = id;\n }\n }\n\n const useConcat: boolean = concatArrayOverhead < simpleArrayOverhead;\n\n const arrayOverhead: number = useConcat ? concatArrayOverhead : simpleArrayOverhead;\n\n useObject = useObject || objectOverhead < arrayOverhead;\n\n if (useObject) {\n // Write an object literal\n let separator: '{' | ',' = '{';\n for (const id of modules) {\n // If the id is legal to use as a key in a JavaScript object literal, use as-is\n const javascriptId: string | number =\n typeof id !== 'string' || validIdRegex.test(id) ? id : JSON.stringify(id);\n source.add(`${separator}${javascriptId}:`);\n separator = ',';\n\n const item: IModuleInfo | undefined = moduleMap.get(id);\n const moduleCode: Source | string = item ? item.source : emptyFunction;\n source.add(moduleCode);\n }\n\n source.add('}');\n } else {\n // Write one or more array literals, joined by Array(gap) expressions\n\n // There will never be more than 16 + (\"\" + minId).length consecutive commas, so 40 is more than will ever be used\n // This is because the above criteria triggers an Array(len) expression instead\n const enoughCommas: string = ',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,';\n\n const useConcatAtStart: boolean = useConcat && minId > 8;\n lastId = useConcatAtStart ? minId : 0;\n // TODO: Just because we want to use concat elsewhere doesn't mean its optimal to use at the start\n let separator: string = useConcatAtStart ? `Array(${minId}).concat([` : '[';\n let concatInserted: boolean = useConcatAtStart;\n for (const id of modules) {\n const delta: number = (id as number) - lastId - 1;\n const deltaStr: string = '' + delta;\n const fillerArrayThreshold: number = 11 + deltaStr.length;\n\n const item: IModuleInfo | undefined = moduleMap.get(id);\n const moduleCode: Source | string = item ? item.source : emptyFunction;\n\n if (useConcat && delta + 1 > fillerArrayThreshold) {\n if (concatInserted) {\n source.add(`],Array(${deltaStr}),[`);\n } else {\n source.add(`].concat(Array(${deltaStr}),[`);\n concatInserted = true;\n }\n } else {\n source.add(separator + enoughCommas.slice(0, delta + 1));\n }\n lastId = id as number;\n source.add(moduleCode);\n\n separator = '';\n }\n\n source.add(useConcat ? '])' : ']');\n }\n\n source.add(suffix);\n\n return handleExternals(new CachedSource(source), asset);\n}\n\nfunction handleExternals(source: Source, asset: IAssetInfo): Source {\n const { externalNames } = asset;\n\n if (externalNames.size) {\n const replaceSource: ReplaceSource = new ReplaceSource(source);\n const code: string = source.source() as string;\n\n const externalIdRegex: RegExp = /__WEBPACK_EXTERNAL_MODULE_[A-Za-z0-9_$]+/g;\n\n // RegExp.exec uses null or an array as the return type, explicitly\n let match: RegExpExecArray | null = null;\n while ((match = externalIdRegex.exec(code))) {\n const id: string = match[0];\n const mapped: string | undefined = externalNames.get(id);\n\n if (mapped === undefined) {\n console.error(`Missing minified external for ${id} in ${asset.fileName}!`);\n } else {\n replaceSource.replace(match.index, externalIdRegex.lastIndex - 1, mapped);\n }\n }\n\n return new CachedSource(replaceSource);\n }\n\n return source;\n}\n"]}
package/lib/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * from './Constants';
2
+ export * from './GenerateLicenseFileForAsset';
3
+ export * from './ModuleMinifierPlugin.types';
4
+ export * from './ModuleMinifierPlugin';
5
+ export * from './PortableMinifierIdsPlugin';
6
+ export * from './RehydrateAsset';
7
+ export type { ILocalMinifierOptions, IMinifierConnection, IModuleMinificationCallback, IModuleMinificationErrorResult, IModuleMinificationRequest, IModuleMinificationResult, IModuleMinificationSuccessResult, IModuleMinifier, IModuleMinifierFunction, IWorkerPoolMinifierOptions } from '@rushstack/module-minifier';
8
+ export { getIdentifier, LocalMinifier, MessagePortMinifier, NoopMinifier, WorkerPoolMinifier } from '@rushstack/module-minifier';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,aAAa,CAAC;AAC5B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,YAAY,EACV,qBAAqB,EACrB,mBAAmB,EACnB,2BAA2B,EAC3B,8BAA8B,EAC9B,0BAA0B,EAC1B,yBAAyB,EACzB,gCAAgC,EAChC,eAAe,EACf,uBAAuB,EACvB,0BAA0B,EAC3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,EACnB,MAAM,4BAA4B,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.WorkerPoolMinifier = exports.NoopMinifier = exports.MessagePortMinifier = exports.LocalMinifier = exports.getIdentifier = void 0;
20
+ __exportStar(require("./Constants"), exports);
21
+ __exportStar(require("./GenerateLicenseFileForAsset"), exports);
22
+ __exportStar(require("./ModuleMinifierPlugin.types"), exports);
23
+ __exportStar(require("./ModuleMinifierPlugin"), exports);
24
+ __exportStar(require("./PortableMinifierIdsPlugin"), exports);
25
+ __exportStar(require("./RehydrateAsset"), exports);
26
+ var module_minifier_1 = require("@rushstack/module-minifier");
27
+ Object.defineProperty(exports, "getIdentifier", { enumerable: true, get: function () { return module_minifier_1.getIdentifier; } });
28
+ Object.defineProperty(exports, "LocalMinifier", { enumerable: true, get: function () { return module_minifier_1.LocalMinifier; } });
29
+ Object.defineProperty(exports, "MessagePortMinifier", { enumerable: true, get: function () { return module_minifier_1.MessagePortMinifier; } });
30
+ Object.defineProperty(exports, "NoopMinifier", { enumerable: true, get: function () { return module_minifier_1.NoopMinifier; } });
31
+ Object.defineProperty(exports, "WorkerPoolMinifier", { enumerable: true, get: function () { return module_minifier_1.WorkerPoolMinifier; } });
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;AAE3D,8CAA4B;AAC5B,gEAA8C;AAC9C,+DAA6C;AAC7C,yDAAuC;AACvC,8DAA4C;AAC5C,mDAAiC;AAajC,8DAMoC;AALlC,gHAAA,aAAa,OAAA;AACb,gHAAA,aAAa,OAAA;AACb,sHAAA,mBAAmB,OAAA;AACnB,+GAAA,YAAY,OAAA;AACZ,qHAAA,kBAAkB,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nexport * from './Constants';\nexport * from './GenerateLicenseFileForAsset';\nexport * from './ModuleMinifierPlugin.types';\nexport * from './ModuleMinifierPlugin';\nexport * from './PortableMinifierIdsPlugin';\nexport * from './RehydrateAsset';\nexport type {\n ILocalMinifierOptions,\n IMinifierConnection,\n IModuleMinificationCallback,\n IModuleMinificationErrorResult,\n IModuleMinificationRequest,\n IModuleMinificationResult,\n IModuleMinificationSuccessResult,\n IModuleMinifier,\n IModuleMinifierFunction,\n IWorkerPoolMinifierOptions\n} from '@rushstack/module-minifier';\nexport {\n getIdentifier,\n LocalMinifier,\n MessagePortMinifier,\n NoopMinifier,\n WorkerPoolMinifier\n} from '@rushstack/module-minifier';\n"]}
@@ -0,0 +1,2 @@
1
+ import '../OverrideWebpackIdentifierAllocation';
2
+ //# sourceMappingURL=WebpackWorker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebpackWorker.d.ts","sourceRoot":"","sources":["../../src/workerPool/WebpackWorker.ts"],"names":[],"mappings":"AAOA,OAAO,wCAAwC,CAAC"}
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || function (mod) {
21
+ if (mod && mod.__esModule) return mod;
22
+ var result = {};
23
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
+ __setModuleDefault(result, mod);
25
+ return result;
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ const webpack = require("webpack");
29
+ const workerThreads = __importStar(require("worker_threads"));
30
+ const module_minifier_1 = require("@rushstack/module-minifier");
31
+ const ModuleMinifierPlugin_1 = require("../ModuleMinifierPlugin");
32
+ require("../OverrideWebpackIdentifierAllocation");
33
+ // Hack to support mkdirp on node 10
34
+ process.umask = () => 0;
35
+ const { configFilePath, sourceMap, usePortableModules } = workerThreads.workerData;
36
+ const webpackConfigs = require(configFilePath); // eslint-disable-line @typescript-eslint/no-var-requires
37
+ // chalk.enabled = enableColor;
38
+ const minifier = new module_minifier_1.MessagePortMinifier(workerThreads.parentPort);
39
+ async function processTaskAsync(index) {
40
+ const config = webpackConfigs[index];
41
+ console.log(`Compiling config: ${config.name || (config.output && config.output.filename)}`);
42
+ const optimization = config.optimization || (config.optimization = {});
43
+ const { minimizer } = optimization;
44
+ if (minimizer) {
45
+ for (const plugin of minimizer) {
46
+ if (plugin instanceof ModuleMinifierPlugin_1.ModuleMinifierPlugin) {
47
+ plugin.minifier = minifier;
48
+ }
49
+ }
50
+ }
51
+ else {
52
+ const { devtool, mode } = config;
53
+ const finalSourceMap = typeof sourceMap === 'boolean'
54
+ ? sourceMap
55
+ : typeof devtool === 'string'
56
+ ? devtool.endsWith('source-map') && !devtool.includes('eval')
57
+ : devtool !== false && mode === 'production';
58
+ optimization.minimizer = [
59
+ new ModuleMinifierPlugin_1.ModuleMinifierPlugin({
60
+ minifier,
61
+ usePortableModules,
62
+ sourceMap: finalSourceMap
63
+ })
64
+ ];
65
+ }
66
+ await new Promise((resolve, reject) => {
67
+ const compiler = webpack(config);
68
+ compiler.run(async (err, stats) => {
69
+ if (err) {
70
+ return reject(err);
71
+ }
72
+ if (stats && stats.hasErrors()) {
73
+ const errorStats = stats.toJson('errors-only');
74
+ errorStats.errors.forEach((error) => {
75
+ console.error(error);
76
+ });
77
+ return reject(new Error(`Webpack failed with ${errorStats.errors.length} error(s).`));
78
+ }
79
+ resolve();
80
+ });
81
+ });
82
+ }
83
+ process.exitCode = 3;
84
+ workerThreads.parentPort.on('message', (message) => {
85
+ // Termination request
86
+ if (message === false) {
87
+ process.exit(0);
88
+ }
89
+ // Input for the MessagePortMinifier
90
+ if (typeof message === 'object') {
91
+ return;
92
+ }
93
+ const index = message;
94
+ processTaskAsync(index).then(() => {
95
+ workerThreads.parentPort.postMessage(index);
96
+ }, (err) => {
97
+ console.error(err);
98
+ process.exit(1);
99
+ });
100
+ });
101
+ //# sourceMappingURL=WebpackWorker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebpackWorker.js","sourceRoot":"","sources":["../../src/workerPool/WebpackWorker.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,mCAAoC;AACpC,8DAAgD;AAChD,gEAAiE;AACjE,kEAA+D;AAC/D,kDAAgD;AAEhD,oCAAoC;AACpC,OAAO,CAAC,KAAK,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC;AAExB,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,kBAAkB,EAAE,GAAG,aAAa,CAAC,UAAU,CAAC;AAEnF,MAAM,cAAc,GAA4B,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,yDAAyD;AAElI,+BAA+B;AAE/B,MAAM,QAAQ,GAAwB,IAAI,qCAAmB,CAAC,aAAa,CAAC,UAAW,CAAC,CAAC;AAEzF,KAAK,UAAU,gBAAgB,CAAC,KAAa;IAC3C,MAAM,MAAM,GAA0B,cAAc,CAAC,KAAK,CAAC,CAAC;IAC5D,OAAO,CAAC,GAAG,CAAC,qBAAqB,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAE7F,MAAM,YAAY,G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C,CAAC,KAAK,EAAE,EAAE;oBAClC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACvB,CAAC,CAAC,CAAC;gBAEH,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,uBAAuB,UAAU,CAAC,MAAM,CAAC,MAAM,YAAY,CAAC,CAAC,CAAC;aACvF;YAED,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AAErB,aAAa,CAAC,UAAW,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAgC,EAAE,EAAE;IAC3E,sBAAsB;IACtB,IAAI,OAAO,KAAK,KAAK,EAAE;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;IAED,oCAAoC;IACpC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,OAAO;KACR;IAED,MAAM,KAAK,GAAW,OAAiB,CAAC;IAExC,gBAAgB,CAAC,KAAK,CAAC,CAAC,IAAI,CAC1B,GAAG,EAAE;QACH,aAAa,CAAC,UAAW,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC,EACD,CAAC,GAAU,EAAE,EAAE;QACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport webpack = require('webpack');\nimport * as workerThreads from 'worker_threads';\nimport { MessagePortMinifier } from '@rushstack/module-minifier';\nimport { ModuleMinifierPlugin } from '../ModuleMinifierPlugin';\nimport '../OverrideWebpackIdentifierAllocation';\n\n// Hack to support mkdirp on node 10\nprocess.umask = () => 0;\n\nconst { configFilePath, sourceMap, usePortableModules } = workerThreads.workerData;\n\nconst webpackConfigs: webpack.Configuration[] = require(configFilePath); // eslint-disable-line @typescript-eslint/no-var-requires\n\n// chalk.enabled = enableColor;\n\nconst minifier: MessagePortMinifier = new MessagePortMinifier(workerThreads.parentPort!);\n\nasync function processTaskAsync(index: number): Promise<void> {\n const config: webpack.Configuration = webpackConfigs[index];\n console.log(`Compiling config: ${config.name || (config.output && config.output.filename)}`);\n\n const optimization: webpack.Options.Optimization = config.optimization || (config.optimization = {});\n const { minimizer } = optimization;\n\n if (minimizer) {\n for (const plugin of minimizer) {\n if (plugin instanceof ModuleMinifierPlugin) {\n plugin.minifier = minifier;\n }\n }\n } else {\n const { devtool, mode } = config;\n\n const finalSourceMap: boolean =\n typeof sourceMap === 'boolean'\n ? sourceMap\n : typeof devtool === 'string'\n ? devtool.endsWith('source-map') && !devtool.includes('eval')\n : devtool !== false && mode === 'production';\n\n optimization.minimizer = [\n new ModuleMinifierPlugin({\n minifier,\n usePortableModules,\n sourceMap: finalSourceMap\n })\n ];\n }\n\n await new Promise<void>((resolve: () => void, reject: (err: Error) => void) => {\n const compiler: webpack.Compiler = webpack(config);\n compiler.run(async (err: Error | undefined, stats: webpack.Stats) => {\n if (err) {\n return reject(err);\n }\n\n if (stats && stats.hasErrors()) {\n const errorStats: webpack.Stats.ToJsonOutput = stats.toJson('errors-only');\n\n errorStats.errors.forEach((error) => {\n console.error(error);\n });\n\n return reject(new Error(`Webpack failed with ${errorStats.errors.length} error(s).`));\n }\n\n resolve();\n });\n });\n}\n\nprocess.exitCode = 3;\n\nworkerThreads.parentPort!.on('message', (message: number | false | object) => {\n // Termination request\n if (message === false) {\n process.exit(0);\n }\n\n // Input for the MessagePortMinifier\n if (typeof message === 'object') {\n return;\n }\n\n const index: number = message as number;\n\n processTaskAsync(index).then(\n () => {\n workerThreads.parentPort!.postMessage(index);\n },\n (err: Error) => {\n console.error(err);\n process.exit(1);\n }\n );\n});\n"]}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@rushstack/webpack4-module-minifier-plugin",
3
+ "version": "0.9.4",
4
+ "description": "This plugin splits minification of webpack compilations into smaller units.",
5
+ "main": "lib/index.js",
6
+ "typings": "dist/webpack4-module-minifier-plugin.d.ts",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/microsoft/rushstack.git",
11
+ "directory": "webpack/module-minifier-plugin-4"
12
+ },
13
+ "engines": {
14
+ "node": ">=10.17.1"
15
+ },
16
+ "peerDependencies": {
17
+ "@types/webpack": "*",
18
+ "@types/webpack-sources": "*",
19
+ "webpack": "^4.31.0",
20
+ "webpack-sources": "~1.4.3"
21
+ },
22
+ "peerDependenciesMeta": {
23
+ "@types/webpack": {
24
+ "optional": true
25
+ },
26
+ "@types/webpack-sources": {
27
+ "optional": true
28
+ }
29
+ },
30
+ "dependencies": {
31
+ "@rushstack/module-minifier": "0.1.5",
32
+ "@rushstack/worker-pool": "0.1.5",
33
+ "@types/node": "12.20.24",
34
+ "@types/tapable": "1.0.6",
35
+ "tapable": "1.1.3"
36
+ },
37
+ "devDependencies": {
38
+ "@rushstack/eslint-config": "2.6.1",
39
+ "@rushstack/heft": "0.45.9",
40
+ "@rushstack/heft-node-rig": "1.9.10",
41
+ "@types/heft-jest": "1.0.1",
42
+ "@types/webpack": "4.41.32",
43
+ "@types/webpack-sources": "1.4.2",
44
+ "webpack": "~4.44.2",
45
+ "webpack-sources": "~1.4.3"
46
+ },
47
+ "sideEffects": [
48
+ "./lib/OverrideWebpackIdentifierAllocation"
49
+ ],
50
+ "scripts": {
51
+ "build": "heft build --clean",
52
+ "_phase:build": "heft build --clean",
53
+ "_phase:test": "heft test --no-build"
54
+ },
55
+ "readme": "# @rushstack/webpack4-module-minifier-plugin\n\n## Installation\n\n`npm install @rushstack/webpack4-module-minifier-plugin --save-dev`\n\n## Overview\n\nThis Webpack plugin performs minification of production assets on a per-module basis, rather than minifying an entire chunk at a time.\nIt issues async calls to the minifier for each unique module and each unique set of chunk boilerplate (i.e. the webpack runtime and the structure of the module list).\nThis improves minification time by:\n- Avoiding duplicate work for each module that is included in multiple distinct assets/chunks (this is common with async chunks)\n- Handing smaller code chunks to the minifier at a time (AST analysis is superlinear in size of the AST)\n- Even single asset builds will likely still contain multiple modules in the final output, which can be split across available CPU cores\n\n## Use with `[hash]` and `[contenthash]` tokens\nThe plugin will do its best to update webpack hashes if changing the direct inputs (`useSourceMap`, `compressAsyncImports` or `usePortableModules`) to the plugin, but if altering the `minifier` property itself, you may need to use the `output.hashSalt` property to force a change to the hashes, especially if leverging the `MessagePortMinifier` or similar, since it has no direct access to the configuration of the minifier.\n\n## Parallel execution\nIf running on node 10, you will need to ensure that the `--experimental-workers` flag is enabled.\n\n```js\nconst { ModuleMinifierPlugin, WorkerPoolMinifier } = require('@rushstack/webpack4-module-minifier-plugin');\n\n// In your webpack options:\noptimization: {\n minimizer: [\n new ModuleMinifierPlugin({\n minifier: new WorkerPoolMinifier(),\n // If not provided, the plugin will attempt to guess from `mode` and `devtool`.\n // Providing it expressly gives better results\n useSourceMap: true\n })\n ]\n}\n```\n\n## Single-threaded execution\nYou can also run the ModuleMinifierPlugin in a single-threaded configuration.\n\n```js\n// webpack.config.js\nconst { ModuleMinifierPlugin, LocalMinifier } = require('@rushstack/webpack4-module-minifier-plugin');\n\n// In your webpack options:\noptimization: {\n minimizer: [\n new ModuleMinifierPlugin({\n minifier: new LocalMinifier()\n })\n ]\n}\n```\n\n## Links\n\n- [CHANGELOG.md](\n https://github.com/microsoft/rushstack/blob/main/webpack/module-minifier-plugin/CHANGELOG.md) - Find\n out what's new in the latest version\n\n`@rushstack/webpack4-module-minifier-plugin` is part of the [Rush Stack](https://rushstack.io/) family of projects.\n"
56
+ }