@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.
- package/LICENSE +24 -0
- package/README.md +61 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/webpack4-module-minifier-plugin.d.ts +346 -0
- package/lib/AsyncImportCompressionPlugin.d.ts +14 -0
- package/lib/AsyncImportCompressionPlugin.d.ts.map +1 -0
- package/lib/AsyncImportCompressionPlugin.js +200 -0
- package/lib/AsyncImportCompressionPlugin.js.map +1 -0
- package/lib/Constants.d.ts +28 -0
- package/lib/Constants.d.ts.map +1 -0
- package/lib/Constants.js +33 -0
- package/lib/Constants.js.map +1 -0
- package/lib/GenerateLicenseFileForAsset.d.ts +13 -0
- package/lib/GenerateLicenseFileForAsset.d.ts.map +1 -0
- package/lib/GenerateLicenseFileForAsset.js +79 -0
- package/lib/GenerateLicenseFileForAsset.js.map +1 -0
- package/lib/ModuleMinifierPlugin.d.ts +18 -0
- package/lib/ModuleMinifierPlugin.d.ts.map +1 -0
- package/lib/ModuleMinifierPlugin.js +439 -0
- package/lib/ModuleMinifierPlugin.js.map +1 -0
- package/lib/ModuleMinifierPlugin.types.d.ts +217 -0
- package/lib/ModuleMinifierPlugin.types.d.ts.map +1 -0
- package/lib/ModuleMinifierPlugin.types.js +5 -0
- package/lib/ModuleMinifierPlugin.types.js.map +1 -0
- package/lib/OverrideWebpackIdentifierAllocation.d.ts +2 -0
- package/lib/OverrideWebpackIdentifierAllocation.d.ts.map +1 -0
- package/lib/OverrideWebpackIdentifierAllocation.js +9 -0
- package/lib/OverrideWebpackIdentifierAllocation.js.map +1 -0
- package/lib/ParallelCompiler.d.ts +11 -0
- package/lib/ParallelCompiler.d.ts.map +1 -0
- package/lib/ParallelCompiler.js +90 -0
- package/lib/ParallelCompiler.js.map +1 -0
- package/lib/PortableMinifierIdsPlugin.d.ts +13 -0
- package/lib/PortableMinifierIdsPlugin.d.ts.map +1 -0
- package/lib/PortableMinifierIdsPlugin.js +129 -0
- package/lib/PortableMinifierIdsPlugin.js.map +1 -0
- package/lib/RehydrateAsset.d.ts +11 -0
- package/lib/RehydrateAsset.d.ts.map +1 -0
- package/lib/RehydrateAsset.js +143 -0
- package/lib/RehydrateAsset.js.map +1 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +32 -0
- package/lib/index.js.map +1 -0
- package/lib/workerPool/WebpackWorker.d.ts +2 -0
- package/lib/workerPool/WebpackWorker.d.ts.map +1 -0
- package/lib/workerPool/WebpackWorker.js +101 -0
- package/lib/workerPool/WebpackWorker.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import type { IModuleMinifier } from '@rushstack/module-minifier';
|
|
2
|
+
import type { AsyncSeriesWaterfallHook, SyncWaterfallHook } from 'tapable';
|
|
3
|
+
import type * as webpack from 'webpack';
|
|
4
|
+
import type { ReplaceSource, Source } from 'webpack-sources';
|
|
5
|
+
/**
|
|
6
|
+
* Information about a dehydrated webpack ECMAScript asset
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface IAssetInfo {
|
|
10
|
+
/**
|
|
11
|
+
* The (minified) boilerplate code for the asset. Will contain a token to be replaced by the minified modules.
|
|
12
|
+
*/
|
|
13
|
+
source: Source;
|
|
14
|
+
/**
|
|
15
|
+
* The name of the asset, used to index into compilation.assets
|
|
16
|
+
*/
|
|
17
|
+
fileName: string;
|
|
18
|
+
/**
|
|
19
|
+
* The ids of the modules that are part of the chunk corresponding to this asset
|
|
20
|
+
*/
|
|
21
|
+
modules: (string | number)[];
|
|
22
|
+
/**
|
|
23
|
+
* The raw chunk object from Webpack, in case information from it is necessary for reconstruction
|
|
24
|
+
*/
|
|
25
|
+
chunk: webpack.compilation.Chunk;
|
|
26
|
+
/**
|
|
27
|
+
* The set of external names to postprocess
|
|
28
|
+
*/
|
|
29
|
+
externalNames: Map<string, string>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Information about a minified module
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export interface IModuleInfo {
|
|
36
|
+
/**
|
|
37
|
+
* The (minified) code of this module. Will be a function expression.
|
|
38
|
+
*/
|
|
39
|
+
source: Source;
|
|
40
|
+
/**
|
|
41
|
+
* The raw module object from Webpack, in case information from it is necessary for reconstruction
|
|
42
|
+
*/
|
|
43
|
+
module: IExtendedModule;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Extension of the webpack Module typings with members that are used by this Plugin
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export interface IExtendedModule extends webpack.compilation.Module {
|
|
50
|
+
/**
|
|
51
|
+
* Is this module external?
|
|
52
|
+
*/
|
|
53
|
+
external?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Concatenated modules
|
|
56
|
+
*/
|
|
57
|
+
modules?: IExtendedModule[];
|
|
58
|
+
/**
|
|
59
|
+
* Recursively scan the dependencies of a module
|
|
60
|
+
*/
|
|
61
|
+
hasDependencies(callback: (dep: webpack.compilation.Dependency) => boolean | void): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Id for the module
|
|
64
|
+
*/
|
|
65
|
+
id: string | number | null;
|
|
66
|
+
/**
|
|
67
|
+
* Gets a descriptive identifier for the module.
|
|
68
|
+
*/
|
|
69
|
+
identifier(): string;
|
|
70
|
+
/**
|
|
71
|
+
* Gets a friendly identifier for the module.
|
|
72
|
+
*/
|
|
73
|
+
readableIdentifier(requestShortener: unknown): string;
|
|
74
|
+
/**
|
|
75
|
+
* Path to the physical file this module represents
|
|
76
|
+
*/
|
|
77
|
+
resource?: string;
|
|
78
|
+
}
|
|
79
|
+
declare module 'webpack' {
|
|
80
|
+
namespace compilation {
|
|
81
|
+
interface RuntimeTemplate {
|
|
82
|
+
requestShortener: webpack.compilation.RequestShortener;
|
|
83
|
+
}
|
|
84
|
+
interface RequestShortener {
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* This is the second parameter to the thisCompilation and compilation webpack.Compiler hooks.
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
export interface _IWebpackCompilationData {
|
|
93
|
+
normalModuleFactory: webpack.compilation.NormalModuleFactory;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* This is the second parameter to the NormalModuleFactory `module` hook
|
|
97
|
+
* @internal
|
|
98
|
+
*/
|
|
99
|
+
export interface _INormalModuleFactoryModuleData {
|
|
100
|
+
resourceResolveData?: {
|
|
101
|
+
/**
|
|
102
|
+
* Contents of the description file (package.json) for the module
|
|
103
|
+
*/
|
|
104
|
+
descriptionFileData?: {
|
|
105
|
+
/**
|
|
106
|
+
* The name of the package
|
|
107
|
+
*/
|
|
108
|
+
name: string;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Absolute path of the description file (package.json) for the module
|
|
112
|
+
*/
|
|
113
|
+
descriptionFilePath?: string;
|
|
114
|
+
/**
|
|
115
|
+
* Absolute path of the directory containing the description file (package.json) for the module
|
|
116
|
+
*/
|
|
117
|
+
descriptionFileRoot?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Relative path from the description file (package.json) to the module
|
|
120
|
+
*/
|
|
121
|
+
relativePath?: string;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* A map from file names to dehydrated assets
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
export declare type IAssetMap = Map<string, IAssetInfo>;
|
|
129
|
+
/**
|
|
130
|
+
* A map from module ids to minified modules
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
export declare type IModuleMap = Map<string | number, IModuleInfo>;
|
|
134
|
+
/**
|
|
135
|
+
* Options to the ModuleMinifierPlugin constructor
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
export interface IModuleMinifierPluginOptions {
|
|
139
|
+
/**
|
|
140
|
+
* Minifier implementation to use. Required.
|
|
141
|
+
*/
|
|
142
|
+
minifier: IModuleMinifier;
|
|
143
|
+
/**
|
|
144
|
+
* Whether to enable source map processing. If not provided, will attempt to guess based on `mode` and `devtool` in the webpack config.
|
|
145
|
+
* Set to `false` for faster builds at the expense of debuggability.
|
|
146
|
+
*/
|
|
147
|
+
sourceMap?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Instructs the plugin to alter the code of modules to maximize portability across compilations.
|
|
150
|
+
*/
|
|
151
|
+
usePortableModules?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Instructs the plugin to alter the code of async import statements to compress better and be portable across compilations.
|
|
154
|
+
*/
|
|
155
|
+
compressAsyncImports?: boolean;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* The set of data remaining to rehydrate in the current compilation
|
|
159
|
+
* @public
|
|
160
|
+
*/
|
|
161
|
+
export interface IDehydratedAssets {
|
|
162
|
+
/**
|
|
163
|
+
* The set of remaining assets to rehydrate. Each tap may remove some or all assets from this collection
|
|
164
|
+
*/
|
|
165
|
+
assets: IAssetMap;
|
|
166
|
+
/**
|
|
167
|
+
* The set of modules to use for rehydrating assets.
|
|
168
|
+
*/
|
|
169
|
+
modules: IModuleMap;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Argument to the postProcessCodeFragment hook for the current execution context
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
export interface IPostProcessFragmentContext {
|
|
176
|
+
/**
|
|
177
|
+
* The current webpack compilation, for error reporting
|
|
178
|
+
*/
|
|
179
|
+
compilation: webpack.compilation.Compilation;
|
|
180
|
+
/**
|
|
181
|
+
* A name to use for logging
|
|
182
|
+
*/
|
|
183
|
+
loggingName: string;
|
|
184
|
+
/**
|
|
185
|
+
* The current module being processed, or `undefined` if not in a module (e.g. the bootstrapper)
|
|
186
|
+
*/
|
|
187
|
+
module: webpack.compilation.Module | undefined;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Hooks provided by the ModuleMinifierPlugin
|
|
191
|
+
* @public
|
|
192
|
+
*/
|
|
193
|
+
export interface IModuleMinifierPluginHooks {
|
|
194
|
+
/**
|
|
195
|
+
* Hook invoked at the start of optimizeChunkAssets to rehydrate the minified boilerplate and runtime into chunk assets.
|
|
196
|
+
*/
|
|
197
|
+
rehydrateAssets: AsyncSeriesWaterfallHook<IDehydratedAssets, webpack.compilation.Compilation>;
|
|
198
|
+
/**
|
|
199
|
+
* Hook invoked on a module id to get the final rendered id.
|
|
200
|
+
*/
|
|
201
|
+
finalModuleId: SyncWaterfallHook<string | number | undefined, webpack.compilation.Compilation>;
|
|
202
|
+
/**
|
|
203
|
+
* Hook invoked on code after it has been returned from the minifier.
|
|
204
|
+
*/
|
|
205
|
+
postProcessCodeFragment: SyncWaterfallHook<ReplaceSource, IPostProcessFragmentContext>;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The comment objects from the Acorn parser inside of webpack
|
|
209
|
+
* @internal
|
|
210
|
+
*/
|
|
211
|
+
export interface _IAcornComment {
|
|
212
|
+
type: 'Line' | 'Block';
|
|
213
|
+
value: string;
|
|
214
|
+
start: number;
|
|
215
|
+
end: number;
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=ModuleMinifierPlugin.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModuleMinifierPlugin.types.d.ts","sourceRoot":"","sources":["../src/ModuleMinifierPlugin.types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE7D;;;G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EAAE,wBAAwB,CAAC,iBAAiB,EAAE,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IAE9F;;OAEG;IACH,aAAa,EAAE,iBAAiB,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IAE/F;;OAEG;IACH,uBAAuB,EAAE,iBAAiB,CAAC,aAAa,EAAE,2BAA2B,CAAC,CAAC;CACxF;AAED;;;GAGG;AAEH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb"}
|
|
@@ -0,0 +1,5 @@
|
|
|
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
|
+
//# sourceMappingURL=ModuleMinifierPlugin.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModuleMinifierPlugin.types.js","sourceRoot":"","sources":["../src/ModuleMinifierPlugin.types.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","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 type { IModuleMinifier } from '@rushstack/module-minifier';\nimport type { AsyncSeriesWaterfallHook, SyncWaterfallHook } from 'tapable';\nimport type * as webpack from 'webpack';\nimport type { ReplaceSource, Source } from 'webpack-sources';\n\n/**\n * Information about a dehydrated webpack ECMAScript asset\n * @public\n */\nexport interface IAssetInfo {\n /**\n * The (minified) boilerplate code for the asset. Will contain a token to be replaced by the minified modules.\n */\n source: Source;\n\n /**\n * The name of the asset, used to index into compilation.assets\n */\n fileName: string;\n\n /**\n * The ids of the modules that are part of the chunk corresponding to this asset\n */\n modules: (string | number)[];\n\n /**\n * The raw chunk object from Webpack, in case information from it is necessary for reconstruction\n */\n chunk: webpack.compilation.Chunk;\n\n /**\n * The set of external names to postprocess\n */\n externalNames: Map<string, string>;\n}\n\n/**\n * Information about a minified module\n * @public\n */\nexport interface IModuleInfo {\n /**\n * The (minified) code of this module. Will be a function expression.\n */\n source: Source;\n\n /**\n * The raw module object from Webpack, in case information from it is necessary for reconstruction\n */\n module: IExtendedModule;\n}\n\n/**\n * Extension of the webpack Module typings with members that are used by this Plugin\n * @public\n */\nexport interface IExtendedModule extends webpack.compilation.Module {\n /**\n * Is this module external?\n */\n external?: boolean;\n /**\n * Concatenated modules\n */\n modules?: IExtendedModule[];\n /**\n * Recursively scan the dependencies of a module\n */\n hasDependencies(callback: (dep: webpack.compilation.Dependency) => boolean | void): boolean;\n /**\n * Id for the module\n */\n // eslint-disable-next-line @rushstack/no-new-null\n id: string | number | null;\n /**\n * Gets a descriptive identifier for the module.\n */\n identifier(): string;\n /**\n * Gets a friendly identifier for the module.\n */\n readableIdentifier(requestShortener: unknown): string;\n /**\n * Path to the physical file this module represents\n */\n resource?: string;\n}\n\ndeclare module 'webpack' {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace compilation {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n interface RuntimeTemplate {\n requestShortener: webpack.compilation.RequestShortener;\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n interface RequestShortener {}\n }\n}\n\n/**\n * This is the second parameter to the thisCompilation and compilation webpack.Compiler hooks.\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface _IWebpackCompilationData {\n normalModuleFactory: webpack.compilation.NormalModuleFactory;\n}\n\n/**\n * This is the second parameter to the NormalModuleFactory `module` hook\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface _INormalModuleFactoryModuleData {\n resourceResolveData?: {\n /**\n * Contents of the description file (package.json) for the module\n */\n descriptionFileData?: {\n /**\n * The name of the package\n */\n name: string;\n };\n /**\n * Absolute path of the description file (package.json) for the module\n */\n descriptionFilePath?: string;\n /**\n * Absolute path of the directory containing the description file (package.json) for the module\n */\n descriptionFileRoot?: string;\n /**\n * Relative path from the description file (package.json) to the module\n */\n relativePath?: string;\n };\n}\n\n/**\n * A map from file names to dehydrated assets\n * @public\n */\nexport type IAssetMap = Map<string, IAssetInfo>;\n/**\n * A map from module ids to minified modules\n * @public\n */\nexport type IModuleMap = Map<string | number, IModuleInfo>;\n\n/**\n * Options to the ModuleMinifierPlugin constructor\n * @public\n */\nexport interface IModuleMinifierPluginOptions {\n /**\n * Minifier implementation to use. Required.\n */\n minifier: IModuleMinifier;\n\n /**\n * Whether to enable source map processing. If not provided, will attempt to guess based on `mode` and `devtool` in the webpack config.\n * Set to `false` for faster builds at the expense of debuggability.\n */\n sourceMap?: boolean;\n\n /**\n * Instructs the plugin to alter the code of modules to maximize portability across compilations.\n */\n usePortableModules?: boolean;\n\n /**\n * Instructs the plugin to alter the code of async import statements to compress better and be portable across compilations.\n */\n compressAsyncImports?: boolean;\n}\n\n/**\n * The set of data remaining to rehydrate in the current compilation\n * @public\n */\nexport interface IDehydratedAssets {\n /**\n * The set of remaining assets to rehydrate. Each tap may remove some or all assets from this collection\n */\n assets: IAssetMap;\n\n /**\n * The set of modules to use for rehydrating assets.\n */\n modules: IModuleMap;\n}\n\n/**\n * Argument to the postProcessCodeFragment hook for the current execution context\n * @public\n */\nexport interface IPostProcessFragmentContext {\n /**\n * The current webpack compilation, for error reporting\n */\n compilation: webpack.compilation.Compilation;\n /**\n * A name to use for logging\n */\n loggingName: string;\n /**\n * The current module being processed, or `undefined` if not in a module (e.g. the bootstrapper)\n */\n module: webpack.compilation.Module | undefined;\n}\n\n/**\n * Hooks provided by the ModuleMinifierPlugin\n * @public\n */\nexport interface IModuleMinifierPluginHooks {\n /**\n * Hook invoked at the start of optimizeChunkAssets to rehydrate the minified boilerplate and runtime into chunk assets.\n */\n rehydrateAssets: AsyncSeriesWaterfallHook<IDehydratedAssets, webpack.compilation.Compilation>;\n\n /**\n * Hook invoked on a module id to get the final rendered id.\n */\n finalModuleId: SyncWaterfallHook<string | number | undefined, webpack.compilation.Compilation>;\n\n /**\n * Hook invoked on code after it has been returned from the minifier.\n */\n postProcessCodeFragment: SyncWaterfallHook<ReplaceSource, IPostProcessFragmentContext>;\n}\n\n/**\n * The comment objects from the Acorn parser inside of webpack\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface _IAcornComment {\n type: 'Line' | 'Block';\n value: string;\n start: number;\n end: number;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OverrideWebpackIdentifierAllocation.d.ts","sourceRoot":"","sources":["../src/OverrideWebpackIdentifierAllocation.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
const webpack_1 = require("webpack");
|
|
6
|
+
const module_minifier_1 = require("@rushstack/module-minifier");
|
|
7
|
+
// Configure webpack to use the same identifier allocation logic as Terser to maximize gzip compressibility
|
|
8
|
+
webpack_1.Template.numberToIdentifer = module_minifier_1.getIdentifier;
|
|
9
|
+
//# sourceMappingURL=OverrideWebpackIdentifierAllocation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OverrideWebpackIdentifierAllocation.js","sourceRoot":"","sources":["../src/OverrideWebpackIdentifierAllocation.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAE3D,qCAAmC;AACnC,gEAA2D;AAE3D,2GAA2G;AAC3G,kBAAQ,CAAC,iBAAiB,GAAG,+BAAa,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 { Template } from 'webpack';\nimport { getIdentifier } from '@rushstack/module-minifier';\n\n// Configure webpack to use the same identifier allocation logic as Terser to maximize gzip compressibility\nTemplate.numberToIdentifer = getIdentifier;\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MinifyOptions } from '@rushstack/module-minifier';
|
|
2
|
+
export interface IParallelWebpackOptions {
|
|
3
|
+
cacheDirectory?: string;
|
|
4
|
+
configFilePath: string;
|
|
5
|
+
maxCompilationThreads?: number;
|
|
6
|
+
sourceMap?: boolean | undefined;
|
|
7
|
+
terserOptions?: MinifyOptions;
|
|
8
|
+
usePortableModules?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function runParallel(options: IParallelWebpackOptions): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=ParallelCompiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ParallelCompiler.d.ts","sourceRoot":"","sources":["../src/ParallelCompiler.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAIV,aAAa,EACd,MAAM,4BAA4B,CAAC;AAIpC,MAAM,WAAW,uBAAuB;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAChC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AA+BD,wBAAsB,WAAW,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAqFjF"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runParallel = void 0;
|
|
4
|
+
const os_1 = require("os");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const module_minifier_1 = require("@rushstack/module-minifier");
|
|
7
|
+
const worker_pool_1 = require("@rushstack/worker-pool");
|
|
8
|
+
const ZERO = BigInt(0);
|
|
9
|
+
const THOUSAND = BigInt(1e3);
|
|
10
|
+
/**
|
|
11
|
+
* Formats a delta of `process.hrtime.bigint()` values as a string
|
|
12
|
+
* @param timeNs
|
|
13
|
+
*/
|
|
14
|
+
function formatTime(timeNs) {
|
|
15
|
+
let unit = 'ns';
|
|
16
|
+
let fraction = ZERO;
|
|
17
|
+
if (timeNs > THOUSAND) {
|
|
18
|
+
unit = 'us';
|
|
19
|
+
fraction = timeNs % THOUSAND;
|
|
20
|
+
timeNs /= THOUSAND;
|
|
21
|
+
}
|
|
22
|
+
if (timeNs > THOUSAND) {
|
|
23
|
+
unit = 'ms';
|
|
24
|
+
fraction = timeNs % THOUSAND;
|
|
25
|
+
timeNs /= THOUSAND;
|
|
26
|
+
}
|
|
27
|
+
if (timeNs > THOUSAND) {
|
|
28
|
+
unit = 's';
|
|
29
|
+
fraction = timeNs % THOUSAND;
|
|
30
|
+
timeNs /= THOUSAND;
|
|
31
|
+
}
|
|
32
|
+
return `${timeNs}.${('000' + fraction).slice(-3, -1)} ${unit}`;
|
|
33
|
+
}
|
|
34
|
+
async function runParallel(options) {
|
|
35
|
+
const resolvedPath = (0, path_1.resolve)(options.configFilePath);
|
|
36
|
+
const rawConfig = require(resolvedPath); // eslint-disable-line @typescript-eslint/no-var-requires
|
|
37
|
+
const configArray = Array.isArray(rawConfig) ? rawConfig : [rawConfig];
|
|
38
|
+
const configCount = configArray.length;
|
|
39
|
+
const totalCpus = (0, os_1.cpus)().length;
|
|
40
|
+
// TODO: Use all cores if not minifying
|
|
41
|
+
const { maxCompilationThreads: maxConfiguredCompilationThreads = Math.max(totalCpus > 8 ? (totalCpus * 3) >> 2 : totalCpus >> 1, 1), sourceMap, usePortableModules } = options;
|
|
42
|
+
const maxCompilationThreads = Math.min(configCount, maxConfiguredCompilationThreads);
|
|
43
|
+
const maxCompressionThreads = Math.max(1, totalCpus - maxCompilationThreads);
|
|
44
|
+
const minifier = new module_minifier_1.WorkerPoolMinifier({
|
|
45
|
+
terserOptions: options.terserOptions,
|
|
46
|
+
maxThreads: maxCompressionThreads
|
|
47
|
+
});
|
|
48
|
+
const minifierConnection = await minifier.connect();
|
|
49
|
+
const webpackPool = new worker_pool_1.WorkerPool({
|
|
50
|
+
id: 'Webpack',
|
|
51
|
+
maxWorkers: maxCompilationThreads,
|
|
52
|
+
onWorkerDestroyed: () => {
|
|
53
|
+
// Allocate the webpack worker to terser
|
|
54
|
+
minifier.maxThreads++;
|
|
55
|
+
},
|
|
56
|
+
workerScriptPath: require.resolve('./workerPool/WebpackWorker'),
|
|
57
|
+
workerData: {
|
|
58
|
+
configFilePath: resolvedPath,
|
|
59
|
+
sourceMap,
|
|
60
|
+
usePortableModules
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
let processed = 0;
|
|
64
|
+
const startTime = process.hrtime.bigint();
|
|
65
|
+
for (let i = 0; i < configCount; i++) {
|
|
66
|
+
const webpackWorker = await webpackPool.checkoutWorkerAsync(true);
|
|
67
|
+
const sendMinifierResult = (result) => {
|
|
68
|
+
webpackWorker.postMessage(result);
|
|
69
|
+
};
|
|
70
|
+
const workerOnMessage = (message) => {
|
|
71
|
+
if (message === 'getConfigHash') {
|
|
72
|
+
webpackWorker.postMessage(minifierConnection.configHash);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (typeof message === 'object') {
|
|
76
|
+
return minifier.minify(message, sendMinifierResult);
|
|
77
|
+
}
|
|
78
|
+
++processed;
|
|
79
|
+
console.log(`${processed}/${configCount} complete (${formatTime(process.hrtime.bigint() - startTime)})`);
|
|
80
|
+
webpackWorker.off('message', workerOnMessage);
|
|
81
|
+
webpackPool.checkinWorker(webpackWorker);
|
|
82
|
+
};
|
|
83
|
+
webpackWorker.on('message', workerOnMessage);
|
|
84
|
+
webpackWorker.postMessage(i);
|
|
85
|
+
}
|
|
86
|
+
await webpackPool.finishAsync();
|
|
87
|
+
await minifierConnection.disconnect();
|
|
88
|
+
}
|
|
89
|
+
exports.runParallel = runParallel;
|
|
90
|
+
//# sourceMappingURL=ParallelCompiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ParallelCompiler.js","sourceRoot":"","sources":["../src/ParallelCompiler.ts"],"names":[],"mappings":";;;AAAA,2BAA0B;AAC1B,+BAA+B;AAW/B,gEAAgE;AAChE,wDAAoD;AAWpD,MAAM,IAAI,GAAW,MAAM,CAAC,CAAC,CAAC,CAAC;AAC/B,MAAM,QAAQ,GAAW,MAAM,CAAC,GAAG,CAAC,CAAC;AAErC;;;GAGG;AACH,SAAS,UAAU,CAAC,MAAc;IAChC,IAAI,IAAI,GAAW,IAAI,CAAC;IACxB,IAAI,QAAQ,GAAW,IAAI,CAAC;IAC5B,IAAI,MAAM,GAAG,QAAQ,EAAE;QACrB,IAAI,GAAG,IAAI,CAAC;QACZ,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC;QAC7B,MAAM,IAAI,QAAQ,CAAC;KACpB;IACD,IAAI,MAAM,GAAG,QAAQ,EAAE;QACrB,IAAI,GAAG,IAAI,CAAC;QACZ,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC;QAC7B,MAAM,IAAI,QAAQ,CAAC;KACpB;IACD,IAAI,MAAM,GAAG,QAAQ,EAAE;QACrB,IAAI,GAAG,GAAG,CAAC;QACX,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC;QAC7B,MAAM,IAAI,QAAQ,CAAC;KACpB;IAED,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;AACjE,CAAC;AAEM,KAAK,UAAU,WAAW,CAAC,OAAgC;IAChE,MAAM,YAAY,GAAW,IAAA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EhC,MAAM,kBAAkB,CAAC,UAAU,EAAE,CAAC;AACxC,CAAC;AArFD,kCAqFC","sourcesContent":["import { cpus } from 'os';\nimport { resolve } from 'path';\nimport { Worker } from 'worker_threads';\n\nimport type { Configuration } from 'webpack';\n\nimport type {\n IMinifierConnection,\n IModuleMinificationRequest,\n IModuleMinificationResult,\n MinifyOptions\n} from '@rushstack/module-minifier';\nimport { WorkerPoolMinifier } from '@rushstack/module-minifier';\nimport { WorkerPool } from '@rushstack/worker-pool';\n\nexport interface IParallelWebpackOptions {\n cacheDirectory?: string;\n configFilePath: string;\n maxCompilationThreads?: number;\n sourceMap?: boolean | undefined;\n terserOptions?: MinifyOptions;\n usePortableModules?: boolean;\n}\n\nconst ZERO: bigint = BigInt(0);\nconst THOUSAND: bigint = BigInt(1e3);\n\n/**\n * Formats a delta of `process.hrtime.bigint()` values as a string\n * @param timeNs\n */\nfunction formatTime(timeNs: bigint): string {\n let unit: string = 'ns';\n let fraction: bigint = ZERO;\n if (timeNs > THOUSAND) {\n unit = 'us';\n fraction = timeNs % THOUSAND;\n timeNs /= THOUSAND;\n }\n if (timeNs > THOUSAND) {\n unit = 'ms';\n fraction = timeNs % THOUSAND;\n timeNs /= THOUSAND;\n }\n if (timeNs > THOUSAND) {\n unit = 's';\n fraction = timeNs % THOUSAND;\n timeNs /= THOUSAND;\n }\n\n return `${timeNs}.${('000' + fraction).slice(-3, -1)} ${unit}`;\n}\n\nexport async function runParallel(options: IParallelWebpackOptions): Promise<void> {\n const resolvedPath: string = resolve(options.configFilePath);\n\n const rawConfig: Configuration | Configuration[] = require(resolvedPath); // eslint-disable-line @typescript-eslint/no-var-requires\n const configArray: Configuration[] = Array.isArray(rawConfig) ? rawConfig : [rawConfig];\n const configCount: number = configArray.length;\n\n const totalCpus: number = cpus().length;\n\n // TODO: Use all cores if not minifying\n const {\n maxCompilationThreads: maxConfiguredCompilationThreads = Math.max(\n totalCpus > 8 ? (totalCpus * 3) >> 2 : totalCpus >> 1,\n 1\n ),\n sourceMap,\n usePortableModules\n } = options;\n\n const maxCompilationThreads: number = Math.min(configCount, maxConfiguredCompilationThreads);\n\n const maxCompressionThreads: number = Math.max(1, totalCpus - maxCompilationThreads);\n\n const minifier: WorkerPoolMinifier = new WorkerPoolMinifier({\n terserOptions: options.terserOptions,\n maxThreads: maxCompressionThreads\n });\n\n const minifierConnection: IMinifierConnection = await minifier.connect();\n\n const webpackPool: WorkerPool = new WorkerPool({\n id: 'Webpack',\n maxWorkers: maxCompilationThreads,\n onWorkerDestroyed: (): void => {\n // Allocate the webpack worker to terser\n minifier.maxThreads++;\n },\n workerScriptPath: require.resolve('./workerPool/WebpackWorker'),\n workerData: {\n configFilePath: resolvedPath,\n sourceMap,\n usePortableModules\n }\n });\n\n let processed: number = 0;\n const startTime: bigint = process.hrtime.bigint();\n\n for (let i: number = 0; i < configCount; i++) {\n const webpackWorker: Worker = await webpackPool.checkoutWorkerAsync(true);\n\n const sendMinifierResult: (result: IModuleMinificationResult) => void = (\n result: IModuleMinificationResult\n ): void => {\n webpackWorker.postMessage(result);\n };\n\n const workerOnMessage: (message: IModuleMinificationRequest | number) => void = (\n message: IModuleMinificationRequest | string | number\n ): void => {\n if (message === 'getConfigHash') {\n webpackWorker.postMessage(minifierConnection.configHash);\n return;\n }\n\n if (typeof message === 'object') {\n return minifier.minify(message, sendMinifierResult);\n }\n\n ++processed;\n console.log(\n `${processed}/${configCount} complete (${formatTime(process.hrtime.bigint() - startTime)})`\n );\n\n webpackWorker.off('message', workerOnMessage);\n webpackPool.checkinWorker(webpackWorker);\n };\n\n webpackWorker.on('message', workerOnMessage);\n webpackWorker.postMessage(i);\n }\n\n await webpackPool.finishAsync();\n\n await minifierConnection.disconnect();\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Compiler, Plugin } from 'webpack';
|
|
2
|
+
import { IModuleMinifierPluginHooks } from './ModuleMinifierPlugin.types';
|
|
3
|
+
/**
|
|
4
|
+
* Plugin responsible for converting the Webpack module ids (of whatever variety) to stable ids before code is handed to the minifier, then back again.
|
|
5
|
+
* Uses the node module identity of the target module. Will emit an error if it encounters multiple versions of the same package in the same compilation.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class PortableMinifierModuleIdsPlugin implements Plugin {
|
|
9
|
+
private readonly _minifierHooks;
|
|
10
|
+
constructor(minifierHooks: IModuleMinifierPluginHooks);
|
|
11
|
+
apply(compiler: Compiler): void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=PortableMinifierIdsPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PortableMinifierIdsPlugin.d.ts","sourceRoot":"","sources":["../src/PortableMinifierIdsPlugin.ts"],"names":[],"mappings":"AAGA,OAAgB,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAOpD,OAAO,EAGL,0BAA0B,EAG3B,MAAM,8BAA8B,CAAC;AAkBtC;;;;GAIG;AACH,qBAAa,+BAAgC,YAAW,MAAM;IAC5D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA6B;gBAEzC,aAAa,EAAE,0BAA0B;IAIrD,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CA4IvC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.PortableMinifierModuleIdsPlugin = void 0;
|
|
9
|
+
const crypto_1 = require("crypto");
|
|
10
|
+
const RequestShortener_1 = __importDefault(require("webpack/lib/RequestShortener"));
|
|
11
|
+
const Constants_1 = require("./Constants");
|
|
12
|
+
const PLUGIN_NAME = 'PortableMinifierModuleIdsPlugin';
|
|
13
|
+
const TAP_BEFORE = {
|
|
14
|
+
name: PLUGIN_NAME,
|
|
15
|
+
stage: Constants_1.STAGE_BEFORE
|
|
16
|
+
};
|
|
17
|
+
const TAP_AFTER = {
|
|
18
|
+
name: PLUGIN_NAME,
|
|
19
|
+
stage: Constants_1.STAGE_AFTER
|
|
20
|
+
};
|
|
21
|
+
const STABLE_MODULE_ID_PREFIX = '__MODULEID_SHA_';
|
|
22
|
+
// The negative lookback here is to ensure that this regex does not match an async import placeholder
|
|
23
|
+
const STABLE_MODULE_ID_REGEX = /(?<!C)['"]?(__MODULEID_SHA_[0-9a-f]+)['"]?/g;
|
|
24
|
+
/**
|
|
25
|
+
* Plugin responsible for converting the Webpack module ids (of whatever variety) to stable ids before code is handed to the minifier, then back again.
|
|
26
|
+
* Uses the node module identity of the target module. Will emit an error if it encounters multiple versions of the same package in the same compilation.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
class PortableMinifierModuleIdsPlugin {
|
|
30
|
+
constructor(minifierHooks) {
|
|
31
|
+
this._minifierHooks = minifierHooks;
|
|
32
|
+
}
|
|
33
|
+
apply(compiler) {
|
|
34
|
+
// Ensure that "EXTERNAL MODULE: " comments are portable and module version invariant
|
|
35
|
+
const baseShorten = RequestShortener_1.default.prototype.shorten;
|
|
36
|
+
RequestShortener_1.default.prototype.shorten = function (request) {
|
|
37
|
+
const baseResult = baseShorten.call(this, request);
|
|
38
|
+
const nodeModules = '/node_modules/';
|
|
39
|
+
if (!baseResult) {
|
|
40
|
+
return baseResult;
|
|
41
|
+
}
|
|
42
|
+
const nodeModulesIndex = baseResult.lastIndexOf(nodeModules);
|
|
43
|
+
if (nodeModulesIndex < 0) {
|
|
44
|
+
return baseResult;
|
|
45
|
+
}
|
|
46
|
+
const nodeModulePath = baseResult.slice(nodeModulesIndex + nodeModules.length);
|
|
47
|
+
this.cache.set(request, nodeModulePath);
|
|
48
|
+
return nodeModulePath;
|
|
49
|
+
};
|
|
50
|
+
const stableIdToFinalId = new Map();
|
|
51
|
+
this._minifierHooks.finalModuleId.tap(PLUGIN_NAME, (id) => {
|
|
52
|
+
return id === undefined ? id : stableIdToFinalId.get(id);
|
|
53
|
+
});
|
|
54
|
+
this._minifierHooks.postProcessCodeFragment.tap(PLUGIN_NAME, (source, context) => {
|
|
55
|
+
const code = source.original().source();
|
|
56
|
+
STABLE_MODULE_ID_REGEX.lastIndex = -1;
|
|
57
|
+
// RegExp.exec uses null or an array as the return type, explicitly
|
|
58
|
+
let match = null;
|
|
59
|
+
while ((match = STABLE_MODULE_ID_REGEX.exec(code))) {
|
|
60
|
+
const id = match[1];
|
|
61
|
+
const mapped = this._minifierHooks.finalModuleId.call(id, context.compilation);
|
|
62
|
+
if (mapped === undefined) {
|
|
63
|
+
context.compilation.errors.push(new Error(`Missing module id for ${id} in ${context.loggingName}!`));
|
|
64
|
+
}
|
|
65
|
+
source.replace(match.index, STABLE_MODULE_ID_REGEX.lastIndex - 1, JSON.stringify(mapped));
|
|
66
|
+
}
|
|
67
|
+
return source;
|
|
68
|
+
});
|
|
69
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation, compilationData) => {
|
|
70
|
+
const { normalModuleFactory } = compilationData;
|
|
71
|
+
normalModuleFactory.hooks.module.tap(PLUGIN_NAME, (mod, data) => {
|
|
72
|
+
const { resourceResolveData: resolveData } = data;
|
|
73
|
+
if (resolveData) {
|
|
74
|
+
mod.factoryMeta.resolveData = resolveData;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
console.error(`Missing resolution data for ${mod.resource}`);
|
|
78
|
+
});
|
|
79
|
+
compilation.hooks.succeedModule.tap(PLUGIN_NAME, (mod) => {
|
|
80
|
+
const { resolveData } = mod.factoryMeta;
|
|
81
|
+
if (!resolveData) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const { descriptionFileData: packageJson, relativePath } = resolveData;
|
|
85
|
+
if (packageJson && relativePath) {
|
|
86
|
+
const nodeId = `${packageJson.name}${relativePath.slice(1).replace(/\.js(on)?$/, '')}`;
|
|
87
|
+
mod.factoryMeta.nodeResource = nodeId;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
stableIdToFinalId.clear();
|
|
91
|
+
// Make module ids a pure function of the file path immediately before rendering.
|
|
92
|
+
// Unfortunately, other means of altering these ids don't work in Webpack 4 without a lot more code and work.
|
|
93
|
+
// Namely, a number of functions reference "module.id" directly during code generation
|
|
94
|
+
compilation.hooks.beforeChunkAssets.tap(TAP_AFTER, () => {
|
|
95
|
+
// For tracking collisions
|
|
96
|
+
const resourceById = new Map();
|
|
97
|
+
for (const mod of compilation.modules) {
|
|
98
|
+
const originalId = mod.id;
|
|
99
|
+
// Need different cache keys for different sets of loaders, so can't use 'resource'
|
|
100
|
+
const identity = mod.identifier();
|
|
101
|
+
const hashId = (0, crypto_1.createHash)('sha256').update(identity).digest('hex');
|
|
102
|
+
// This is designed to be an easily regex-findable string
|
|
103
|
+
const stableId = `${STABLE_MODULE_ID_PREFIX}${hashId}`;
|
|
104
|
+
const existingResource = resourceById.get(stableId);
|
|
105
|
+
if (existingResource) {
|
|
106
|
+
compilation.errors.push(new Error(`Module id collision for ${identity} with ${existingResource}.\n This means you are bundling multiple versions of the same module.`));
|
|
107
|
+
}
|
|
108
|
+
stableIdToFinalId.set(stableId, originalId);
|
|
109
|
+
// Record to detect collisions
|
|
110
|
+
resourceById.set(stableId, identity);
|
|
111
|
+
mod.id = stableId;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
// This is the hook immediately following chunk asset rendering. Fix the module ids.
|
|
115
|
+
compilation.hooks.additionalChunkAssets.tap(TAP_BEFORE, () => {
|
|
116
|
+
// Restore module ids in case any later hooks need them
|
|
117
|
+
for (const mod of compilation.modules) {
|
|
118
|
+
const stableId = mod.id;
|
|
119
|
+
const finalId = stableIdToFinalId.get(stableId);
|
|
120
|
+
if (finalId !== undefined) {
|
|
121
|
+
mod.id = finalId;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.PortableMinifierModuleIdsPlugin = PortableMinifierModuleIdsPlugin;
|
|
129
|
+
//# sourceMappingURL=PortableMinifierIdsPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PortableMinifierIdsPlugin.js","sourceRoot":"","sources":["../src/PortableMinifierIdsPlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAI3D,mCAAoC;AAEpC,oFAA4D;AAE5D,2CAAwD;AASxD,MAAM,WAAW,GAAsC,iCAAiC,CAAC;AAEzF,MAAM,UAAU,GAAuB;IACrC,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE,wBAAY;CACpB,CAAC;AAEF,MAAM,SAAS,GAAuB;IACpC,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE,uBAAW;CACnB,CAAC;AAEF,MAAM,uBAAuB,GAAsB,iBAAiB,CAAC;AACrE,qGAAqG;AACrG,MAAM,sBAAsB,GAAW,6CAA6C,CAAC;AAErF;;;;GAIG;AACH,MAAa,+BAA+B;IAG1C,YAAmB,aAAyC;QAC1D,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACtC,CAAC;IAEM,KAAK,CAAC,QAAkB;QAC7B,qFAAqF;QACrF,MAAM,WAAW,GAAgC,0BAAgB,CAAC,SAAS,CAAC,OAAO,CAAC;QACpF,0BAAgB,CAAC,SAAS,CAAC,OAAO,GAAG,UAAkC,OAAe;YACpF,MAAM,UAAU,GAAW,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC3D,MAAM,WAAW,GAAqB,gBAAgB,CAAC;YAEvD,IAAI,CAAC,UAAU,EAAE;gBACf,OAAO,UAAU,CAAC;aACnB;YAED,MAAM,gBAAgB,GAAW,UAAU,CAAC,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qB,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,EAAE;gBAC3D,uDAAuD;gBACvD,KAAK,MAAM,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE;oBACrC,MAAM,QAAQ,GAAoB,GAAG,CAAC,EAAE,CAAC;oBACzC,MAAM,OAAO,GAAgC,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;oBAC7E,IAAI,OAAO,KAAK,SAAS,EAAE;wBACzB,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC;qBAClB;iBACF;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAnJD,0EAmJC","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, { Compiler, Plugin } from 'webpack';\nimport { ReplaceSource } from 'webpack-sources';\nimport { createHash } from 'crypto';\nimport { TapOptions } from 'tapable';\nimport RequestShortener from 'webpack/lib/RequestShortener';\n\nimport { STAGE_AFTER, STAGE_BEFORE } from './Constants';\nimport {\n _INormalModuleFactoryModuleData,\n IExtendedModule,\n IModuleMinifierPluginHooks,\n _IWebpackCompilationData,\n IPostProcessFragmentContext\n} from './ModuleMinifierPlugin.types';\n\nconst PLUGIN_NAME: 'PortableMinifierModuleIdsPlugin' = 'PortableMinifierModuleIdsPlugin';\n\nconst TAP_BEFORE: TapOptions<'sync'> = {\n name: PLUGIN_NAME,\n stage: STAGE_BEFORE\n};\n\nconst TAP_AFTER: TapOptions<'sync'> = {\n name: PLUGIN_NAME,\n stage: STAGE_AFTER\n};\n\nconst STABLE_MODULE_ID_PREFIX: '__MODULEID_SHA_' = '__MODULEID_SHA_';\n// The negative lookback here is to ensure that this regex does not match an async import placeholder\nconst STABLE_MODULE_ID_REGEX: RegExp = /(?<!C)['\"]?(__MODULEID_SHA_[0-9a-f]+)['\"]?/g;\n\n/**\n * Plugin responsible for converting the Webpack module ids (of whatever variety) to stable ids before code is handed to the minifier, then back again.\n * Uses the node module identity of the target module. Will emit an error if it encounters multiple versions of the same package in the same compilation.\n * @public\n */\nexport class PortableMinifierModuleIdsPlugin implements Plugin {\n private readonly _minifierHooks: IModuleMinifierPluginHooks;\n\n public constructor(minifierHooks: IModuleMinifierPluginHooks) {\n this._minifierHooks = minifierHooks;\n }\n\n public apply(compiler: Compiler): void {\n // Ensure that \"EXTERNAL MODULE: \" comments are portable and module version invariant\n const baseShorten: (request: string) => string = RequestShortener.prototype.shorten;\n RequestShortener.prototype.shorten = function (this: RequestShortener, request: string): string {\n const baseResult: string = baseShorten.call(this, request);\n const nodeModules: '/node_modules/' = '/node_modules/';\n\n if (!baseResult) {\n return baseResult;\n }\n\n const nodeModulesIndex: number = baseResult.lastIndexOf(nodeModules);\n if (nodeModulesIndex < 0) {\n return baseResult;\n }\n\n const nodeModulePath: string = baseResult.slice(nodeModulesIndex + nodeModules.length);\n this.cache.set(request, nodeModulePath);\n return nodeModulePath;\n };\n\n const stableIdToFinalId: Map<string | number, string | number> = new Map();\n\n this._minifierHooks.finalModuleId.tap(PLUGIN_NAME, (id: string | number | undefined) => {\n return id === undefined ? id : stableIdToFinalId.get(id);\n });\n\n this._minifierHooks.postProcessCodeFragment.tap(\n PLUGIN_NAME,\n (source: ReplaceSource, context: IPostProcessFragmentContext) => {\n const code: string = source.original().source() as string;\n\n STABLE_MODULE_ID_REGEX.lastIndex = -1;\n // RegExp.exec uses null or an array as the return type, explicitly\n let match: RegExpExecArray | null = null;\n while ((match = STABLE_MODULE_ID_REGEX.exec(code))) {\n const id: string = match[1];\n const mapped: string | number | undefined = this._minifierHooks.finalModuleId.call(\n id,\n context.compilation\n );\n\n if (mapped === undefined) {\n context.compilation.errors.push(\n new Error(`Missing module id for ${id} in ${context.loggingName}!`)\n );\n }\n\n source.replace(match.index, STABLE_MODULE_ID_REGEX.lastIndex - 1, JSON.stringify(mapped));\n }\n\n return source;\n }\n );\n\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: webpack.compilation.Compilation, compilationData: _IWebpackCompilationData) => {\n const { normalModuleFactory } = compilationData;\n\n normalModuleFactory.hooks.module.tap(\n PLUGIN_NAME,\n (mod: IExtendedModule, data: _INormalModuleFactoryModuleData) => {\n const { resourceResolveData: resolveData } = data;\n\n if (resolveData) {\n mod.factoryMeta.resolveData = resolveData;\n return;\n }\n\n console.error(`Missing resolution data for ${mod.resource}`);\n }\n );\n\n compilation.hooks.succeedModule.tap(PLUGIN_NAME, (mod: webpack.compilation.Module) => {\n const { resolveData } = mod.factoryMeta;\n\n if (!resolveData) {\n return;\n }\n\n const { descriptionFileData: packageJson, relativePath } = resolveData;\n\n if (packageJson && relativePath) {\n const nodeId: string = `${packageJson.name}${relativePath.slice(1).replace(/\\.js(on)?$/, '')}`;\n mod.factoryMeta.nodeResource = nodeId;\n }\n });\n\n stableIdToFinalId.clear();\n\n // Make module ids a pure function of the file path immediately before rendering.\n // Unfortunately, other means of altering these ids don't work in Webpack 4 without a lot more code and work.\n // Namely, a number of functions reference \"module.id\" directly during code generation\n\n compilation.hooks.beforeChunkAssets.tap(TAP_AFTER, () => {\n // For tracking collisions\n const resourceById: Map<string | number, string> = new Map();\n\n for (const mod of compilation.modules) {\n const originalId: string | number = mod.id;\n\n // Need different cache keys for different sets of loaders, so can't use 'resource'\n const identity: string = mod.identifier();\n const hashId: string = createHash('sha256').update(identity).digest('hex');\n\n // This is designed to be an easily regex-findable string\n const stableId: string = `${STABLE_MODULE_ID_PREFIX}${hashId}`;\n const existingResource: string | undefined = resourceById.get(stableId);\n\n if (existingResource) {\n compilation.errors.push(\n new Error(\n `Module id collision for ${identity} with ${existingResource}.\\n This means you are bundling multiple versions of the same module.`\n )\n );\n }\n\n stableIdToFinalId.set(stableId, originalId);\n\n // Record to detect collisions\n resourceById.set(stableId, identity);\n mod.id = stableId;\n }\n });\n\n // This is the hook immediately following chunk asset rendering. Fix the module ids.\n compilation.hooks.additionalChunkAssets.tap(TAP_BEFORE, () => {\n // Restore module ids in case any later hooks need them\n for (const mod of compilation.modules) {\n const stableId: string | number = mod.id;\n const finalId: string | number | undefined = stableIdToFinalId.get(stableId);\n if (finalId !== undefined) {\n mod.id = finalId;\n }\n }\n });\n }\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Source } from 'webpack-sources';
|
|
2
|
+
import { IAssetInfo, IModuleMap } from './ModuleMinifierPlugin.types';
|
|
3
|
+
/**
|
|
4
|
+
* Rehydrates an asset with minified modules.
|
|
5
|
+
* @param asset - The asset
|
|
6
|
+
* @param moduleMap - The minified modules
|
|
7
|
+
* @param banner - A banner to inject for license information
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare function rehydrateAsset(asset: IAssetInfo, moduleMap: IModuleMap, banner: string): Source;
|
|
11
|
+
//# sourceMappingURL=RehydrateAsset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RehydrateAsset.d.ts","sourceRoot":"","sources":["../src/RehydrateAsset.ts"],"names":[],"mappings":"AAGA,OAAO,EAA6C,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGpF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAe,MAAM,8BAA8B,CAAC;AAEnF;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAkI/F"}
|