@rushstack/webpack4-module-minifier-plugin 0.11.4 → 0.12.1
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/dist/webpack4-module-minifier-plugin.d.ts +38 -1
- package/lib/ModuleMinifierPlugin.d.ts +2 -1
- package/lib/ModuleMinifierPlugin.d.ts.map +1 -1
- package/lib/ModuleMinifierPlugin.js +20 -1
- package/lib/ModuleMinifierPlugin.js.map +1 -1
- package/lib/ModuleMinifierPlugin.types.d.ts +32 -0
- package/lib/ModuleMinifierPlugin.types.d.ts.map +1 -1
- package/lib/ModuleMinifierPlugin.types.js.map +1 -1
- package/lib/RehydrateAsset.d.ts +2 -1
- package/lib/RehydrateAsset.d.ts.map +1 -1
- package/lib/RehydrateAsset.js +31 -5
- package/lib/RehydrateAsset.js.map +1 -1
- package/package.json +5 -5
|
@@ -68,6 +68,10 @@ export declare interface IAssetInfo {
|
|
|
68
68
|
* The ids of the modules that are part of the chunk corresponding to this asset
|
|
69
69
|
*/
|
|
70
70
|
modules: (string | number)[];
|
|
71
|
+
/**
|
|
72
|
+
* Information about the offsets and character lengths for each rendered module in the final asset.
|
|
73
|
+
*/
|
|
74
|
+
renderInfo: Map<string | number, IRenderedModulePosition>;
|
|
71
75
|
/**
|
|
72
76
|
* The raw chunk object from Webpack, in case information from it is necessary for reconstruction
|
|
73
77
|
*/
|
|
@@ -84,6 +88,14 @@ export declare interface IAssetInfo {
|
|
|
84
88
|
*/
|
|
85
89
|
export declare type IAssetMap = Map<string, IAssetInfo>;
|
|
86
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Rendered positional data
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
95
|
+
export declare interface IAssetStats {
|
|
96
|
+
positionByModuleId: Map<string | number, IRenderedModulePosition>;
|
|
97
|
+
}
|
|
98
|
+
|
|
87
99
|
/**
|
|
88
100
|
* The set of data remaining to rehydrate in the current compilation
|
|
89
101
|
* @public
|
|
@@ -216,6 +228,14 @@ export declare interface IModuleMinifierPluginOptions {
|
|
|
216
228
|
compressAsyncImports?: boolean;
|
|
217
229
|
}
|
|
218
230
|
|
|
231
|
+
/**
|
|
232
|
+
* Statistics from the plugin. Namely module sizes.
|
|
233
|
+
* @public
|
|
234
|
+
*/
|
|
235
|
+
export declare interface IModuleMinifierPluginStats {
|
|
236
|
+
metadataByAssetFileName: Map<string, IAssetStats>;
|
|
237
|
+
}
|
|
238
|
+
|
|
219
239
|
/**
|
|
220
240
|
* This is the second parameter to the NormalModuleFactory `module` hook
|
|
221
241
|
* @internal
|
|
@@ -265,6 +285,21 @@ export declare interface IPostProcessFragmentContext {
|
|
|
265
285
|
module: webpack.compilation.Module | undefined;
|
|
266
286
|
}
|
|
267
287
|
|
|
288
|
+
/**
|
|
289
|
+
* Information about where the module was rendered in the emitted asset.
|
|
290
|
+
* @public
|
|
291
|
+
*/
|
|
292
|
+
export declare interface IRenderedModulePosition {
|
|
293
|
+
/**
|
|
294
|
+
* The offset from the start of tha asset to the start of the module, in characters.
|
|
295
|
+
*/
|
|
296
|
+
charOffset: number;
|
|
297
|
+
/**
|
|
298
|
+
* The length of the rendered module, in characters.
|
|
299
|
+
*/
|
|
300
|
+
charLength: number;
|
|
301
|
+
}
|
|
302
|
+
|
|
268
303
|
/**
|
|
269
304
|
* This is the second parameter to the thisCompilation and compilation webpack.Compiler hooks.
|
|
270
305
|
* @internal
|
|
@@ -304,6 +339,7 @@ export declare class ModuleMinifierPlugin implements webpack.Plugin {
|
|
|
304
339
|
private readonly _sourceMap;
|
|
305
340
|
private readonly _optionsForHash;
|
|
306
341
|
constructor(options: IModuleMinifierPluginOptions);
|
|
342
|
+
static getCompilationStatistics(compilation: webpack.compilation.Compilation): IModuleMinifierPluginStats | undefined;
|
|
307
343
|
apply(compiler: webpack.Compiler): void;
|
|
308
344
|
}
|
|
309
345
|
|
|
@@ -325,9 +361,10 @@ export declare class PortableMinifierModuleIdsPlugin implements Plugin {
|
|
|
325
361
|
* @param asset - The asset
|
|
326
362
|
* @param moduleMap - The minified modules
|
|
327
363
|
* @param banner - A banner to inject for license information
|
|
364
|
+
* @param emitRenderInfo - If set, provide information about module offsets
|
|
328
365
|
* @public
|
|
329
366
|
*/
|
|
330
|
-
export declare function rehydrateAsset(asset: IAssetInfo, moduleMap: IModuleMap, banner: string): Source;
|
|
367
|
+
export declare function rehydrateAsset(asset: IAssetInfo, moduleMap: IModuleMap, banner: string, emitRenderInfo?: boolean): Source;
|
|
331
368
|
|
|
332
369
|
/**
|
|
333
370
|
* Stage # to use when this should be the last tap in the hook
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as webpack from 'webpack';
|
|
2
2
|
import type { IModuleMinifier } from '@rushstack/module-minifier';
|
|
3
|
-
import { IModuleMinifierPluginOptions, IModuleMinifierPluginHooks } from './ModuleMinifierPlugin.types';
|
|
3
|
+
import type { IModuleMinifierPluginOptions, IModuleMinifierPluginHooks, IModuleMinifierPluginStats } from './ModuleMinifierPlugin.types';
|
|
4
4
|
import './OverrideWebpackIdentifierAllocation';
|
|
5
5
|
/**
|
|
6
6
|
* Webpack plugin that minifies code on a per-module basis rather than per-asset. The actual minification is handled by the input `minifier` object.
|
|
@@ -13,6 +13,7 @@ export declare class ModuleMinifierPlugin implements webpack.Plugin {
|
|
|
13
13
|
private readonly _sourceMap;
|
|
14
14
|
private readonly _optionsForHash;
|
|
15
15
|
constructor(options: IModuleMinifierPluginOptions);
|
|
16
|
+
static getCompilationStatistics(compilation: webpack.compilation.Compilation): IModuleMinifierPluginStats | undefined;
|
|
16
17
|
apply(compiler: webpack.Compiler): void;
|
|
17
18
|
}
|
|
18
19
|
//# sourceMappingURL=ModuleMinifierPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModuleMinifierPlugin.d.ts","sourceRoot":"","sources":["../src/ModuleMinifierPlugin.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAUnC,OAAO,KAAK,EAEV,eAAe,EAGhB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,
|
|
1
|
+
{"version":3,"file":"ModuleMinifierPlugin.d.ts","sourceRoot":"","sources":["../src/ModuleMinifierPlugin.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAUnC,OAAO,KAAK,EAEV,eAAe,EAGhB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,KAAK,EACV,4BAA4B,EAI5B,0BAA0B,EAK1B,0BAA0B,EAE3B,MAAM,8BAA8B,CAAC;AAMtC,OAAO,uCAAuC,CAAC;AA4G/C;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,OAAO,CAAC,MAAM;IACzD,SAAgB,KAAK,EAAE,0BAA0B,CAAC;IAC3C,QAAQ,EAAE,eAAe,CAAC;IAEjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;IAEjD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkB;gBAE/B,OAAO,EAAE,4BAA4B;WAiC1C,wBAAwB,CACpC,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,WAAW,GAC3C,0BAA0B,GAAG,SAAS;IAIlC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI;CAib/C"}
|
|
@@ -50,6 +50,7 @@ const TAP_AFTER = {
|
|
|
50
50
|
name: PLUGIN_NAME,
|
|
51
51
|
stage: Constants_1.STAGE_AFTER
|
|
52
52
|
};
|
|
53
|
+
const compilationMetadataMap = new WeakMap();
|
|
53
54
|
/**
|
|
54
55
|
* https://github.com/webpack/webpack/blob/30e747a55d9e796ae22f67445ae42c7a95a6aa48/lib/Template.js#L36-47
|
|
55
56
|
* @param a first id to be sorted
|
|
@@ -76,12 +77,20 @@ function hashCodeFragment(code) {
|
|
|
76
77
|
*/
|
|
77
78
|
function defaultRehydrateAssets(dehydratedAssets, compilation) {
|
|
78
79
|
const { assets, modules } = dehydratedAssets;
|
|
80
|
+
const compilationMetadata = compilationMetadataMap.get(compilation);
|
|
81
|
+
if (!compilationMetadata) {
|
|
82
|
+
throw new Error(`Could not get compilation metadata`);
|
|
83
|
+
}
|
|
84
|
+
const { metadataByAssetFileName } = compilationMetadata;
|
|
79
85
|
// Now assets/modules contain fully minified code. Rehydrate.
|
|
80
86
|
for (const [assetName, info] of assets) {
|
|
81
87
|
const banner = /\.m?js(\?.+)?$/.test(assetName)
|
|
82
88
|
? (0, GenerateLicenseFileForAsset_1.generateLicenseFileForAsset)(compilation, info, modules)
|
|
83
89
|
: '';
|
|
84
|
-
const outputSource = (0, RehydrateAsset_1.rehydrateAsset)(info, modules, banner);
|
|
90
|
+
const outputSource = (0, RehydrateAsset_1.rehydrateAsset)(info, modules, banner, true);
|
|
91
|
+
metadataByAssetFileName.set(assetName, {
|
|
92
|
+
positionByModuleId: info.renderInfo
|
|
93
|
+
});
|
|
85
94
|
compilation.assets[assetName] = outputSource;
|
|
86
95
|
}
|
|
87
96
|
return dehydratedAssets;
|
|
@@ -122,6 +131,9 @@ class ModuleMinifierPlugin {
|
|
|
122
131
|
this.minifier = minifier;
|
|
123
132
|
this._sourceMap = sourceMap;
|
|
124
133
|
}
|
|
134
|
+
static getCompilationStatistics(compilation) {
|
|
135
|
+
return compilationMetadataMap.get(compilation);
|
|
136
|
+
}
|
|
125
137
|
apply(compiler) {
|
|
126
138
|
for (const enhancer of this._enhancers) {
|
|
127
139
|
enhancer.apply(compiler);
|
|
@@ -157,6 +169,11 @@ class ModuleMinifierPlugin {
|
|
|
157
169
|
* The text and comments of all minified chunks. Most of these are trivial, but the runtime chunk is a bit larger.
|
|
158
170
|
*/
|
|
159
171
|
const minifiedAssets = new Map();
|
|
172
|
+
const metadataByAssetFileName = new Map();
|
|
173
|
+
const compilationStatistics = {
|
|
174
|
+
metadataByAssetFileName
|
|
175
|
+
};
|
|
176
|
+
compilationMetadataMap.set(compilation, compilationStatistics);
|
|
160
177
|
let pendingMinificationRequests = 0;
|
|
161
178
|
/**
|
|
162
179
|
* Indicates that all files have been sent to the minifier and therefore that when pending hits 0, assets can be rehydrated.
|
|
@@ -363,6 +380,7 @@ class ModuleMinifierPlugin {
|
|
|
363
380
|
modules: chunkModules,
|
|
364
381
|
chunk,
|
|
365
382
|
fileName: assetName,
|
|
383
|
+
renderInfo: new Map(),
|
|
366
384
|
externalNames
|
|
367
385
|
});
|
|
368
386
|
}
|
|
@@ -385,6 +403,7 @@ class ModuleMinifierPlugin {
|
|
|
385
403
|
modules: chunkModules,
|
|
386
404
|
chunk,
|
|
387
405
|
fileName: assetName,
|
|
406
|
+
renderInfo: new Map(),
|
|
388
407
|
externalNames
|
|
389
408
|
});
|
|
390
409
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModuleMinifierPlugin.js","sourceRoot":"","sources":["../src/ModuleMinifierPlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,mCAA0C;AAE1C,qDAOyB;AACzB,iDAAmC;AACnC,qCAA4F;AAE5F,2CAMqB;AAOrB,gEAA2D;AAa3D,+EAA4E;AAC5E,qDAAkD;AAClD,iFAA8E;AAC9E,2EAA8E;AAE9E,iDAA+C;AAE/C,0CAA0C;AAC1C,MAAM,WAAW,GAA2B,sBAAsB,CAAC;AAEnE,mGAAmG;AACnG,uCAAuC;AACvC,MAAM,wBAAwB,GAAW,CAAC,CAAC;AAE3C,MAAM,UAAU,GAA0B;IACxC,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE,wBAAY;CACpB,CAAC;AACF,MAAM,SAAS,GAAuB;IACpC,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE,uBAAW;CACnB,CAAC;AAwBF;;;;;GAKG;AACH,SAAS,wBAAwB,CAAC,CAAkB,EAAE,CAAkB;IACtE,MAAM,GAAG,GAAW,CAAC,GAAG,EAAE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EAAE,EAAE;gBAC5E,IAAI,cAAc,KAAK,WAAW,CAAC,eAAe,CAAC,UAAU,EAAE;oBAC7D,iCAAiC;oBACjC,OAAO,MAAM,CAAC;iBACf;gBAED,+BAA+B;gBAC/B,OAAO,IAAI,2BAAS,CAAC,+BAAmB,CAAC,CAAC;YAC5C,CAAC,CACF,CAAC;YAED,WAAW,CAAC,YAAkD,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAC/E,SAAS,EACT,CAAC,MAAc,EAAE,KAAgC,EAAE,IAAa,EAAE,cAAuB,EAAE,EAAE;gBAC3F,IAAI,cAAc,KAAK,WAAW,CAAC,eAAe,CAAC,UAAU,EAAE;oBAC7D,iCAAiC;oBACjC,OAAO,MAAM,CAAC;iBACf;gBAED,+BAA+B;gBAC/B,OAAO,IAAI,2BAAS,CAAC,+BAAmB,CAAC,CAAC;YAC5C,CAAC,CACF,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAndD,oDAmdC","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 { createHash, Hash } from 'crypto';\n\nimport {\n CachedSource,\n ConcatSource,\n RawSource,\n ReplaceSource,\n Source,\n SourceMapSource\n} from 'webpack-sources';\nimport * as webpack from 'webpack';\nimport { AsyncSeriesWaterfallHook, SyncHook, SyncWaterfallHook, TapOptions } from 'tapable';\n\nimport {\n CHUNK_MODULES_TOKEN,\n MODULE_WRAPPER_PREFIX,\n MODULE_WRAPPER_SUFFIX,\n STAGE_BEFORE,\n STAGE_AFTER\n} from './Constants';\nimport type {\n IMinifierConnection,\n IModuleMinifier,\n IModuleMinificationResult,\n IModuleMinificationErrorResult\n} from '@rushstack/module-minifier';\nimport { getIdentifier } from '@rushstack/module-minifier';\n\nimport {\n IModuleMinifierPluginOptions,\n IModuleMap,\n IAssetMap,\n IExtendedModule,\n IModuleMinifierPluginHooks,\n IPostProcessFragmentContext,\n IDehydratedAssets,\n _IWebpackCompilationData,\n _IAcornComment\n} from './ModuleMinifierPlugin.types';\nimport { generateLicenseFileForAsset } from './GenerateLicenseFileForAsset';\nimport { rehydrateAsset } from './RehydrateAsset';\nimport { AsyncImportCompressionPlugin } from './AsyncImportCompressionPlugin';\nimport { PortableMinifierModuleIdsPlugin } from './PortableMinifierIdsPlugin';\n\nimport './OverrideWebpackIdentifierAllocation';\n\n// The name of the plugin, for use in taps\nconst PLUGIN_NAME: 'ModuleMinifierPlugin' = 'ModuleMinifierPlugin';\n\n// Monotonically increasing identifier to be incremented any time the code generation logic changes\n// Will be applied to the webpack hash.\nconst CODE_GENERATION_REVISION: number = 1;\n\nconst TAP_BEFORE: TapOptions<'promise'> = {\n name: PLUGIN_NAME,\n stage: STAGE_BEFORE\n};\nconst TAP_AFTER: TapOptions<'sync'> = {\n name: PLUGIN_NAME,\n stage: STAGE_AFTER\n};\n\ninterface IExtendedChunkTemplate {\n hooks: {\n hashForChunk: SyncHook<Hash, webpack.compilation.Chunk>;\n modules: SyncWaterfallHook<Source, webpack.compilation.Chunk>;\n };\n}\n\ninterface IExtendedParser extends webpack.compilation.normalModuleFactory.Parser {\n state: {\n module: IExtendedModule;\n };\n}\n\ninterface IExtendedModuleTemplate extends webpack.compilation.ModuleTemplate {\n render: (module: IExtendedModule, dependencyTemplates: unknown, options: unknown) => Source;\n}\n\ninterface IOptionsForHash extends Omit<IModuleMinifierPluginOptions, 'minifier'> {\n revision: number;\n minifier: undefined;\n}\n\n/**\n * https://github.com/webpack/webpack/blob/30e747a55d9e796ae22f67445ae42c7a95a6aa48/lib/Template.js#L36-47\n * @param a first id to be sorted\n * @param b second id to be sorted against\n * @returns the sort value\n */\nfunction stringifyIdSortPredicate(a: string | number, b: string | number): -1 | 0 | 1 {\n const aId: string = a + '';\n const bId: string = b + '';\n if (aId < bId) return -1;\n if (aId > bId) return 1;\n return 0;\n}\n\nfunction hashCodeFragment(code: string): string {\n return createHash('sha256').update(code).digest('hex');\n}\n\n/**\n * Base implementation of asset rehydration\n *\n * @param dehydratedAssets The dehydrated assets\n * @param compilation The webpack compilation\n */\nfunction defaultRehydrateAssets(\n dehydratedAssets: IDehydratedAssets,\n compilation: webpack.compilation.Compilation\n): IDehydratedAssets {\n const { assets, modules } = dehydratedAssets;\n\n // Now assets/modules contain fully minified code. Rehydrate.\n for (const [assetName, info] of assets) {\n const banner: string = /\\.m?js(\\?.+)?$/.test(assetName)\n ? generateLicenseFileForAsset(compilation, info, modules)\n : '';\n\n const outputSource: Source = rehydrateAsset(info, modules, banner);\n compilation.assets[assetName] = outputSource;\n }\n\n return dehydratedAssets;\n}\n\nfunction isMinificationResultError(\n result: IModuleMinificationResult\n): result is IModuleMinificationErrorResult {\n return !!result.error;\n}\n\n// Matche behavior of terser's \"some\" option\nfunction isLicenseComment(comment: _IAcornComment): boolean {\n // https://github.com/terser/terser/blob/d3d924fa9e4c57bbe286b811c6068bcc7026e902/lib/output.js#L175\n return /@preserve|@lic|@cc_on|^\\**!/i.test(comment.value);\n}\n\n/**\n * Webpack plugin that minifies code on a per-module basis rather than per-asset. The actual minification is handled by the input `minifier` object.\n * @public\n */\nexport class ModuleMinifierPlugin implements webpack.Plugin {\n public readonly hooks: IModuleMinifierPluginHooks;\n public minifier: IModuleMinifier;\n\n private readonly _enhancers: webpack.Plugin[];\n private readonly _sourceMap: boolean | undefined;\n\n private readonly _optionsForHash: IOptionsForHash;\n\n public constructor(options: IModuleMinifierPluginOptions) {\n this.hooks = {\n rehydrateAssets: new AsyncSeriesWaterfallHook(['dehydratedContent', 'compilation']),\n\n finalModuleId: new SyncWaterfallHook(['id']),\n\n postProcessCodeFragment: new SyncWaterfallHook(['code', 'context'])\n };\n\n const { minifier, sourceMap, usePortableModules = false, compressAsyncImports = false } = options;\n\n this._optionsForHash = {\n ...options,\n minifier: undefined,\n revision: CODE_GENERATION_REVISION\n };\n\n this._enhancers = [];\n\n if (usePortableModules) {\n this._enhancers.push(new PortableMinifierModuleIdsPlugin(this.hooks));\n }\n\n if (compressAsyncImports) {\n this._enhancers.push(new AsyncImportCompressionPlugin(this.hooks));\n }\n\n this.hooks.rehydrateAssets.tap(PLUGIN_NAME, defaultRehydrateAssets);\n this.minifier = minifier;\n\n this._sourceMap = sourceMap;\n }\n\n public apply(compiler: webpack.Compiler): void {\n for (const enhancer of this._enhancers) {\n enhancer.apply(compiler);\n }\n\n const {\n options: { devtool, mode }\n } = compiler;\n // The explicit setting is preferred due to accuracy, but try to guess based on devtool\n const useSourceMaps: boolean =\n typeof this._sourceMap === 'boolean'\n ? this._sourceMap\n : typeof devtool === 'string'\n ? devtool.endsWith('source-map')\n : mode === 'production' && devtool !== false;\n\n this._optionsForHash.sourceMap = useSourceMaps;\n const binaryConfig: Uint8Array = Buffer.from(JSON.stringify(this._optionsForHash), 'utf-8');\n\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: webpack.compilation.Compilation, compilationData: _IWebpackCompilationData) => {\n const { normalModuleFactory } = compilationData;\n\n function addCommentExtraction(parser: webpack.compilation.normalModuleFactory.Parser): void {\n parser.hooks.program.tap(PLUGIN_NAME, (program: unknown, comments: _IAcornComment[]) => {\n (parser as IExtendedParser).state.module.factoryMeta.comments = comments.filter(isLicenseComment);\n });\n }\n\n normalModuleFactory.hooks.parser.for('javascript/auto').tap(PLUGIN_NAME, addCommentExtraction);\n normalModuleFactory.hooks.parser.for('javascript/dynamic').tap(PLUGIN_NAME, addCommentExtraction);\n normalModuleFactory.hooks.parser.for('javascript/esm').tap(PLUGIN_NAME, addCommentExtraction);\n\n /**\n * Set of local module ids that have been processed.\n */\n const submittedModules: Set<string | number> = new Set();\n\n /**\n * The text and comments of all minified modules.\n */\n const minifiedModules: IModuleMap = new Map();\n\n /**\n * The text and comments of all minified chunks. Most of these are trivial, but the runtime chunk is a bit larger.\n */\n const minifiedAssets: IAssetMap = new Map();\n\n let pendingMinificationRequests: number = 0;\n /**\n * Indicates that all files have been sent to the minifier and therefore that when pending hits 0, assets can be rehydrated.\n */\n let allRequestsIssued: boolean = false;\n\n let resolveMinifyPromise: () => void;\n\n const getRealId: (id: number | string) => number | string | undefined = (id: number | string) =>\n this.hooks.finalModuleId.call(id, compilation);\n\n const postProcessCode: (\n code: ReplaceSource,\n context: IPostProcessFragmentContext\n ) => ReplaceSource = (code: ReplaceSource, context: IPostProcessFragmentContext) =>\n this.hooks.postProcessCodeFragment.call(code, context);\n\n /**\n * Callback to invoke when a file has finished minifying.\n */\n function onFileMinified(): void {\n if (--pendingMinificationRequests === 0 && allRequestsIssued) {\n resolveMinifyPromise();\n }\n }\n\n const { minifier } = this;\n\n let minifierConnection: IMinifierConnection | undefined;\n\n const requestShortener: webpack.compilation.RequestShortener =\n compilation.runtimeTemplate.requestShortener;\n\n /**\n * Extracts the code for the module and sends it to be minified.\n * Currently source maps are explicitly not supported.\n * @param {Source} source\n * @param {Module} mod\n */\n function minifyModule(source: Source, mod: IExtendedModule): Source {\n const id: string | number | null = mod.id;\n\n if (id !== null && !submittedModules.has(id)) {\n // options.chunk contains the current chunk, if needed\n // Render the source, then hash, then persist hash -> module, return a placeholder\n\n // Initially populate the map with unminified version; replace during callback\n submittedModules.add(id);\n\n const realId: string | number | undefined = getRealId(id);\n\n if (realId !== undefined && !mod.factoryMeta.skipMinification) {\n const wrapped: ConcatSource = new ConcatSource(\n MODULE_WRAPPER_PREFIX + '\\n',\n source,\n '\\n' + MODULE_WRAPPER_SUFFIX\n );\n\n const nameForMap: string = `(modules)/${realId}`;\n\n const { source: wrappedCode, map } = useSourceMaps\n ? wrapped.sourceAndMap()\n : {\n source: wrapped.source(),\n map: undefined\n };\n\n const hash: string = hashCodeFragment(wrappedCode);\n\n ++pendingMinificationRequests;\n\n minifier.minify(\n {\n hash,\n code: wrappedCode,\n nameForMap: useSourceMaps ? nameForMap : undefined,\n externals: undefined\n },\n (result: IModuleMinificationResult) => {\n if (isMinificationResultError(result)) {\n compilation.errors.push(result.error);\n } else {\n try {\n // Have the source map display the module id instead of the minifier boilerplate\n const sourceForMap: string = `// ${mod.readableIdentifier(\n requestShortener\n )}${wrappedCode.slice(MODULE_WRAPPER_PREFIX.length, -MODULE_WRAPPER_SUFFIX.length)}`;\n\n const { code: minified, map: minifierMap } = result;\n\n const rawOutput: Source = useSourceMaps\n ? new SourceMapSource(\n minified, // Code\n nameForMap, // File\n minifierMap!, // Base source map\n sourceForMap, // Source from before transform\n map!, // Source Map from before transform\n false // Remove original source\n )\n : new RawSource(minified);\n\n const unwrapped: ReplaceSource = new ReplaceSource(rawOutput);\n const len: number = minified.length;\n\n unwrapped.replace(0, MODULE_WRAPPER_PREFIX.length - 1, '');\n unwrapped.replace(len - MODULE_WRAPPER_SUFFIX.length, len - 1, '');\n\n const withIds: Source = postProcessCode(unwrapped, {\n compilation,\n module: mod,\n loggingName: mod.identifier()\n });\n const cached: CachedSource = new CachedSource(withIds);\n\n const minifiedSize: number = Buffer.byteLength(cached.source(), 'utf-8');\n mod.factoryMeta.minifiedSize = minifiedSize;\n\n minifiedModules.set(realId, {\n source: cached,\n module: mod\n });\n } catch (err) {\n compilation.errors.push(err);\n }\n }\n\n onFileMinified();\n }\n );\n } else {\n // Route any other modules straight through\n const cached: CachedSource = new CachedSource(\n postProcessCode(new ReplaceSource(source), {\n compilation,\n module: mod,\n loggingName: mod.identifier()\n })\n );\n\n const minifiedSize: number = Buffer.byteLength(cached.source(), 'utf-8');\n mod.factoryMeta.minifiedSize = minifiedSize;\n\n minifiedModules.set(realId !== undefined ? realId : id, {\n source: cached,\n module: mod\n });\n }\n }\n\n // Return something so that this stage still produces valid ECMAScript\n return new RawSource('(function(){})');\n }\n\n const jsTemplate: IExtendedModuleTemplate = compilation.moduleTemplates\n .javascript as IExtendedModuleTemplate;\n const innerRender: IExtendedModuleTemplate['render'] = jsTemplate.render.bind(jsTemplate);\n\n // The optimizeTree hook is the last async hook that occurs before chunk rendering\n compilation.hooks.optimizeTree.tapPromise(PLUGIN_NAME, async () => {\n minifierConnection = await minifier.connect();\n\n submittedModules.clear();\n\n const cache: WeakSet<IExtendedModule> = new WeakSet();\n const defaultSource: Source = new RawSource('');\n\n // During code generation, send the generated code to the minifier and replace with a placeholder\n // Hacking this to avoid calling .source() on a concatenated module multiple times\n jsTemplate.render = (module: IExtendedModule, dependencyTemplates, options) => {\n if (!cache.has(module)) {\n cache.add(module);\n const rendered: Source = innerRender(module, dependencyTemplates, options);\n\n minifyModule(rendered, module);\n }\n\n return defaultSource;\n };\n });\n\n // This should happen before any other tasks that operate during optimizeChunkAssets\n compilation.hooks.optimizeChunkAssets.tapPromise(\n TAP_BEFORE,\n async (chunks: webpack.compilation.Chunk[]): Promise<void> => {\n // Still need to minify the rendered assets\n for (const chunk of chunks) {\n const externals: string[] = [];\n const externalNames: Map<string, string> = new Map();\n\n const chunkModuleSet: Set<string | number> = new Set();\n const allChunkModules: Iterable<IExtendedModule> =\n chunk.modulesIterable as Iterable<IExtendedModule>;\n let hasNonNumber: boolean = false;\n for (const mod of allChunkModules) {\n if (mod.id !== null) {\n if (typeof mod.id !== 'number') {\n hasNonNumber = true;\n }\n chunkModuleSet.add(mod.id);\n\n if (mod.external) {\n // Match the identifiers generated in the AmdMainTemplatePlugin\n // https://github.com/webpack/webpack/blob/444e59f8a427f94f0064cae6765e5a3c4b78596d/lib/AmdMainTemplatePlugin.js#L49\n const key: string = `__WEBPACK_EXTERNAL_MODULE_${webpack.Template.toIdentifier(\n `${mod.id}`\n )}__`;\n // The first two identifiers are used for function (module, exports) at the module site\n const ordinal: number = 2 + externals.length;\n const miniId: string = getIdentifier(ordinal);\n externals.push(key);\n externalNames.set(key, miniId);\n }\n }\n }\n\n const chunkModules: (string | number)[] = Array.from(chunkModuleSet);\n // Sort by id before rehydration in case we rehydrate a given chunk multiple times\n chunkModules.sort(\n hasNonNumber\n ? stringifyIdSortPredicate\n : (x: string | number, y: string | number) => (x as number) - (y as number)\n );\n\n for (const assetName of chunk.files) {\n const asset: Source = compilation.assets[assetName];\n\n // Verify that this is a JS asset\n if (/\\.m?js(\\?.+)?$/.test(assetName)) {\n ++pendingMinificationRequests;\n\n const rawCode: string = asset.source() as string;\n const nameForMap: string = `(chunks)/${assetName}`;\n\n const hash: string = hashCodeFragment(rawCode);\n\n minifier.minify(\n {\n hash,\n code: rawCode,\n nameForMap: useSourceMaps ? nameForMap : undefined,\n externals\n },\n (result: IModuleMinificationResult) => {\n if (isMinificationResultError(result)) {\n compilation.errors.push(result.error);\n console.error(result.error);\n } else {\n try {\n const { code: minified, map: minifierMap } = result;\n\n let codeForMap: string = rawCode;\n if (useSourceMaps) {\n // Pretend the __WEBPACK_CHUNK_MODULES__ token is an array of module ids, so that the source map contains information about the module ids in the chunk\n codeForMap = codeForMap.replace(\n CHUNK_MODULES_TOKEN,\n JSON.stringify(chunkModules, undefined, 2)\n );\n }\n\n const rawOutput: Source = useSourceMaps\n ? new SourceMapSource(\n minified, // Code\n nameForMap, // File\n minifierMap!, // Base source map\n codeForMap, // Source from before transform\n undefined, // Source Map from before transform\n false // Remove original source\n )\n : new RawSource(minified);\n\n const withIds: Source = postProcessCode(new ReplaceSource(rawOutput), {\n compilation,\n module: undefined,\n loggingName: assetName\n });\n\n minifiedAssets.set(assetName, {\n source: new CachedSource(withIds),\n modules: chunkModules,\n chunk,\n fileName: assetName,\n externalNames\n });\n } catch (err) {\n compilation.errors.push(err);\n }\n }\n\n onFileMinified();\n }\n );\n } else {\n // This isn't a JS asset. Don't try to minify the asset wrapper, though if it contains modules, those might still get replaced with minified versions.\n minifiedAssets.set(assetName, {\n // Still need to restore ids\n source: postProcessCode(new ReplaceSource(asset), {\n compilation,\n module: undefined,\n loggingName: assetName\n }),\n modules: chunkModules,\n chunk,\n fileName: assetName,\n externalNames\n });\n }\n }\n }\n\n allRequestsIssued = true;\n\n if (pendingMinificationRequests) {\n await new Promise<void>((resolve) => {\n resolveMinifyPromise = resolve;\n });\n }\n\n // Handle any error from the minifier.\n await minifierConnection?.disconnect();\n\n // All assets and modules have been minified, hand them off to be rehydrated\n await this.hooks.rehydrateAssets.promise(\n {\n assets: minifiedAssets,\n modules: minifiedModules\n },\n compilation\n );\n }\n );\n\n function updateChunkHash(hash: Hash, chunk: webpack.compilation.Chunk): void {\n // Apply the options hash\n hash.update(binaryConfig);\n // Apply the hash from the minifier\n if (minifierConnection) {\n hash.update(minifierConnection.configHash, 'utf8');\n }\n }\n\n // Need to update chunk hashes with information from this plugin\n (compilation.chunkTemplate as unknown as IExtendedChunkTemplate).hooks.hashForChunk.tap(\n PLUGIN_NAME,\n updateChunkHash\n );\n compilation.mainTemplate.hooks.hashForChunk.tap(PLUGIN_NAME, updateChunkHash);\n\n // This function is written twice because the parameter order is not the same between the two hooks\n (compilation.chunkTemplate as unknown as IExtendedChunkTemplate).hooks.modules.tap(\n TAP_AFTER,\n (source: Source, chunk: webpack.compilation.Chunk, moduleTemplate: unknown) => {\n if (moduleTemplate !== compilation.moduleTemplates.javascript) {\n // This is not a JavaScript asset\n return source;\n }\n\n // Discard the rendered modules\n return new RawSource(CHUNK_MODULES_TOKEN);\n }\n );\n\n (compilation.mainTemplate as unknown as IExtendedChunkTemplate).hooks.modules.tap(\n TAP_AFTER,\n (source: Source, chunk: webpack.compilation.Chunk, hash: unknown, moduleTemplate: unknown) => {\n if (moduleTemplate !== compilation.moduleTemplates.javascript) {\n // This is not a JavaScript asset\n return source;\n }\n\n // Discard the rendered modules\n return new RawSource(CHUNK_MODULES_TOKEN);\n }\n );\n }\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ModuleMinifierPlugin.js","sourceRoot":"","sources":["../src/ModuleMinifierPlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,mCAA0C;AAE1C,qDAOyB;AACzB,iDAAmC;AACnC,qCAA4F;AAE5F,2CAMqB;AAOrB,gEAA2D;AAe3D,+EAA4E;AAC5E,qDAAkD;AAClD,iFAA8E;AAC9E,2EAA8E;AAE9E,iDAA+C;AAE/C,0CA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MAAM,CAAC;iBACf;gBAED,+BAA+B;gBAC/B,OAAO,IAAI,2BAAS,CAAC,+BAAmB,CAAC,CAAC;YAC5C,CAAC,CACF,CAAC;YAED,WAAW,CAAC,YAAkD,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAC/E,SAAS,EACT,CAAC,MAAc,EAAE,KAAgC,EAAE,IAAa,EAAE,cAAuB,EAAE,EAAE;gBAC3F,IAAI,cAAc,KAAK,WAAW,CAAC,eAAe,CAAC,UAAU,EAAE;oBAC7D,iCAAiC;oBACjC,OAAO,MAAM,CAAC;iBACf;gBAED,+BAA+B;gBAC/B,OAAO,IAAI,2BAAS,CAAC,+BAAmB,CAAC,CAAC;YAC5C,CAAC,CACF,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAjeD,oDAieC","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 { createHash, Hash } from 'crypto';\n\nimport {\n CachedSource,\n ConcatSource,\n RawSource,\n ReplaceSource,\n Source,\n SourceMapSource\n} from 'webpack-sources';\nimport * as webpack from 'webpack';\nimport { AsyncSeriesWaterfallHook, SyncHook, SyncWaterfallHook, TapOptions } from 'tapable';\n\nimport {\n CHUNK_MODULES_TOKEN,\n MODULE_WRAPPER_PREFIX,\n MODULE_WRAPPER_SUFFIX,\n STAGE_BEFORE,\n STAGE_AFTER\n} from './Constants';\nimport type {\n IMinifierConnection,\n IModuleMinifier,\n IModuleMinificationResult,\n IModuleMinificationErrorResult\n} from '@rushstack/module-minifier';\nimport { getIdentifier } from '@rushstack/module-minifier';\n\nimport type {\n IModuleMinifierPluginOptions,\n IModuleMap,\n IAssetMap,\n IExtendedModule,\n IModuleMinifierPluginHooks,\n IPostProcessFragmentContext,\n IDehydratedAssets,\n _IWebpackCompilationData,\n _IAcornComment,\n IModuleMinifierPluginStats,\n IAssetStats\n} from './ModuleMinifierPlugin.types';\nimport { generateLicenseFileForAsset } from './GenerateLicenseFileForAsset';\nimport { rehydrateAsset } from './RehydrateAsset';\nimport { AsyncImportCompressionPlugin } from './AsyncImportCompressionPlugin';\nimport { PortableMinifierModuleIdsPlugin } from './PortableMinifierIdsPlugin';\n\nimport './OverrideWebpackIdentifierAllocation';\n\n// The name of the plugin, for use in taps\nconst PLUGIN_NAME: 'ModuleMinifierPlugin' = 'ModuleMinifierPlugin';\n\n// Monotonically increasing identifier to be incremented any time the code generation logic changes\n// Will be applied to the webpack hash.\nconst CODE_GENERATION_REVISION: number = 1;\n\nconst TAP_BEFORE: TapOptions<'promise'> = {\n name: PLUGIN_NAME,\n stage: STAGE_BEFORE\n};\nconst TAP_AFTER: TapOptions<'sync'> = {\n name: PLUGIN_NAME,\n stage: STAGE_AFTER\n};\n\ninterface IExtendedChunkTemplate {\n hooks: {\n hashForChunk: SyncHook<Hash, webpack.compilation.Chunk>;\n modules: SyncWaterfallHook<Source, webpack.compilation.Chunk>;\n };\n}\n\ninterface IExtendedParser extends webpack.compilation.normalModuleFactory.Parser {\n state: {\n module: IExtendedModule;\n };\n}\n\ninterface IExtendedModuleTemplate extends webpack.compilation.ModuleTemplate {\n render: (module: IExtendedModule, dependencyTemplates: unknown, options: unknown) => Source;\n}\n\ninterface IOptionsForHash extends Omit<IModuleMinifierPluginOptions, 'minifier'> {\n revision: number;\n minifier: undefined;\n}\n\nconst compilationMetadataMap: WeakMap<webpack.compilation.Compilation, IModuleMinifierPluginStats> =\n new WeakMap();\n\n/**\n * https://github.com/webpack/webpack/blob/30e747a55d9e796ae22f67445ae42c7a95a6aa48/lib/Template.js#L36-47\n * @param a first id to be sorted\n * @param b second id to be sorted against\n * @returns the sort value\n */\nfunction stringifyIdSortPredicate(a: string | number, b: string | number): -1 | 0 | 1 {\n const aId: string = a + '';\n const bId: string = b + '';\n if (aId < bId) return -1;\n if (aId > bId) return 1;\n return 0;\n}\n\nfunction hashCodeFragment(code: string): string {\n return createHash('sha256').update(code).digest('hex');\n}\n\n/**\n * Base implementation of asset rehydration\n *\n * @param dehydratedAssets The dehydrated assets\n * @param compilation The webpack compilation\n */\nfunction defaultRehydrateAssets(\n dehydratedAssets: IDehydratedAssets,\n compilation: webpack.compilation.Compilation\n): IDehydratedAssets {\n const { assets, modules } = dehydratedAssets;\n\n const compilationMetadata: IModuleMinifierPluginStats | undefined = compilationMetadataMap.get(compilation);\n if (!compilationMetadata) {\n throw new Error(`Could not get compilation metadata`);\n }\n\n const { metadataByAssetFileName } = compilationMetadata;\n\n // Now assets/modules contain fully minified code. Rehydrate.\n for (const [assetName, info] of assets) {\n const banner: string = /\\.m?js(\\?.+)?$/.test(assetName)\n ? generateLicenseFileForAsset(compilation, info, modules)\n : '';\n\n const outputSource: Source = rehydrateAsset(info, modules, banner, true);\n metadataByAssetFileName.set(assetName, {\n positionByModuleId: info.renderInfo\n });\n compilation.assets[assetName] = outputSource;\n }\n\n return dehydratedAssets;\n}\n\nfunction isMinificationResultError(\n result: IModuleMinificationResult\n): result is IModuleMinificationErrorResult {\n return !!result.error;\n}\n\n// Matche behavior of terser's \"some\" option\nfunction isLicenseComment(comment: _IAcornComment): boolean {\n // https://github.com/terser/terser/blob/d3d924fa9e4c57bbe286b811c6068bcc7026e902/lib/output.js#L175\n return /@preserve|@lic|@cc_on|^\\**!/i.test(comment.value);\n}\n\n/**\n * Webpack plugin that minifies code on a per-module basis rather than per-asset. The actual minification is handled by the input `minifier` object.\n * @public\n */\nexport class ModuleMinifierPlugin implements webpack.Plugin {\n public readonly hooks: IModuleMinifierPluginHooks;\n public minifier: IModuleMinifier;\n\n private readonly _enhancers: webpack.Plugin[];\n private readonly _sourceMap: boolean | undefined;\n\n private readonly _optionsForHash: IOptionsForHash;\n\n public constructor(options: IModuleMinifierPluginOptions) {\n this.hooks = {\n rehydrateAssets: new AsyncSeriesWaterfallHook(['dehydratedContent', 'compilation']),\n\n finalModuleId: new SyncWaterfallHook(['id']),\n\n postProcessCodeFragment: new SyncWaterfallHook(['code', 'context'])\n };\n\n const { minifier, sourceMap, usePortableModules = false, compressAsyncImports = false } = options;\n\n this._optionsForHash = {\n ...options,\n minifier: undefined,\n revision: CODE_GENERATION_REVISION\n };\n\n this._enhancers = [];\n\n if (usePortableModules) {\n this._enhancers.push(new PortableMinifierModuleIdsPlugin(this.hooks));\n }\n\n if (compressAsyncImports) {\n this._enhancers.push(new AsyncImportCompressionPlugin(this.hooks));\n }\n\n this.hooks.rehydrateAssets.tap(PLUGIN_NAME, defaultRehydrateAssets);\n this.minifier = minifier;\n\n this._sourceMap = sourceMap;\n }\n\n public static getCompilationStatistics(\n compilation: webpack.compilation.Compilation\n ): IModuleMinifierPluginStats | undefined {\n return compilationMetadataMap.get(compilation);\n }\n\n public apply(compiler: webpack.Compiler): void {\n for (const enhancer of this._enhancers) {\n enhancer.apply(compiler);\n }\n\n const {\n options: { devtool, mode }\n } = compiler;\n // The explicit setting is preferred due to accuracy, but try to guess based on devtool\n const useSourceMaps: boolean =\n typeof this._sourceMap === 'boolean'\n ? this._sourceMap\n : typeof devtool === 'string'\n ? devtool.endsWith('source-map')\n : mode === 'production' && devtool !== false;\n\n this._optionsForHash.sourceMap = useSourceMaps;\n const binaryConfig: Uint8Array = Buffer.from(JSON.stringify(this._optionsForHash), 'utf-8');\n\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: webpack.compilation.Compilation, compilationData: _IWebpackCompilationData) => {\n const { normalModuleFactory } = compilationData;\n\n function addCommentExtraction(parser: webpack.compilation.normalModuleFactory.Parser): void {\n parser.hooks.program.tap(PLUGIN_NAME, (program: unknown, comments: _IAcornComment[]) => {\n (parser as IExtendedParser).state.module.factoryMeta.comments = comments.filter(isLicenseComment);\n });\n }\n\n normalModuleFactory.hooks.parser.for('javascript/auto').tap(PLUGIN_NAME, addCommentExtraction);\n normalModuleFactory.hooks.parser.for('javascript/dynamic').tap(PLUGIN_NAME, addCommentExtraction);\n normalModuleFactory.hooks.parser.for('javascript/esm').tap(PLUGIN_NAME, addCommentExtraction);\n\n /**\n * Set of local module ids that have been processed.\n */\n const submittedModules: Set<string | number> = new Set();\n\n /**\n * The text and comments of all minified modules.\n */\n const minifiedModules: IModuleMap = new Map();\n\n /**\n * The text and comments of all minified chunks. Most of these are trivial, but the runtime chunk is a bit larger.\n */\n const minifiedAssets: IAssetMap = new Map();\n\n const metadataByAssetFileName: Map<string, IAssetStats> = new Map();\n const compilationStatistics: IModuleMinifierPluginStats = {\n metadataByAssetFileName\n };\n compilationMetadataMap.set(compilation, compilationStatistics);\n\n let pendingMinificationRequests: number = 0;\n /**\n * Indicates that all files have been sent to the minifier and therefore that when pending hits 0, assets can be rehydrated.\n */\n let allRequestsIssued: boolean = false;\n\n let resolveMinifyPromise: () => void;\n\n const getRealId: (id: number | string) => number | string | undefined = (id: number | string) =>\n this.hooks.finalModuleId.call(id, compilation);\n\n const postProcessCode: (\n code: ReplaceSource,\n context: IPostProcessFragmentContext\n ) => ReplaceSource = (code: ReplaceSource, context: IPostProcessFragmentContext) =>\n this.hooks.postProcessCodeFragment.call(code, context);\n\n /**\n * Callback to invoke when a file has finished minifying.\n */\n function onFileMinified(): void {\n if (--pendingMinificationRequests === 0 && allRequestsIssued) {\n resolveMinifyPromise();\n }\n }\n\n const { minifier } = this;\n\n let minifierConnection: IMinifierConnection | undefined;\n\n const requestShortener: webpack.compilation.RequestShortener =\n compilation.runtimeTemplate.requestShortener;\n\n /**\n * Extracts the code for the module and sends it to be minified.\n * Currently source maps are explicitly not supported.\n * @param {Source} source\n * @param {Module} mod\n */\n function minifyModule(source: Source, mod: IExtendedModule): Source {\n const id: string | number | null = mod.id;\n\n if (id !== null && !submittedModules.has(id)) {\n // options.chunk contains the current chunk, if needed\n // Render the source, then hash, then persist hash -> module, return a placeholder\n\n // Initially populate the map with unminified version; replace during callback\n submittedModules.add(id);\n\n const realId: string | number | undefined = getRealId(id);\n\n if (realId !== undefined && !mod.factoryMeta.skipMinification) {\n const wrapped: ConcatSource = new ConcatSource(\n MODULE_WRAPPER_PREFIX + '\\n',\n source,\n '\\n' + MODULE_WRAPPER_SUFFIX\n );\n\n const nameForMap: string = `(modules)/${realId}`;\n\n const { source: wrappedCode, map } = useSourceMaps\n ? wrapped.sourceAndMap()\n : {\n source: wrapped.source(),\n map: undefined\n };\n\n const hash: string = hashCodeFragment(wrappedCode);\n\n ++pendingMinificationRequests;\n\n minifier.minify(\n {\n hash,\n code: wrappedCode,\n nameForMap: useSourceMaps ? nameForMap : undefined,\n externals: undefined\n },\n (result: IModuleMinificationResult) => {\n if (isMinificationResultError(result)) {\n compilation.errors.push(result.error);\n } else {\n try {\n // Have the source map display the module id instead of the minifier boilerplate\n const sourceForMap: string = `// ${mod.readableIdentifier(\n requestShortener\n )}${wrappedCode.slice(MODULE_WRAPPER_PREFIX.length, -MODULE_WRAPPER_SUFFIX.length)}`;\n\n const { code: minified, map: minifierMap } = result;\n\n const rawOutput: Source = useSourceMaps\n ? new SourceMapSource(\n minified, // Code\n nameForMap, // File\n minifierMap!, // Base source map\n sourceForMap, // Source from before transform\n map!, // Source Map from before transform\n false // Remove original source\n )\n : new RawSource(minified);\n\n const unwrapped: ReplaceSource = new ReplaceSource(rawOutput);\n const len: number = minified.length;\n\n unwrapped.replace(0, MODULE_WRAPPER_PREFIX.length - 1, '');\n unwrapped.replace(len - MODULE_WRAPPER_SUFFIX.length, len - 1, '');\n\n const withIds: Source = postProcessCode(unwrapped, {\n compilation,\n module: mod,\n loggingName: mod.identifier()\n });\n const cached: CachedSource = new CachedSource(withIds);\n\n const minifiedSize: number = Buffer.byteLength(cached.source(), 'utf-8');\n mod.factoryMeta.minifiedSize = minifiedSize;\n\n minifiedModules.set(realId, {\n source: cached,\n module: mod\n });\n } catch (err) {\n compilation.errors.push(err);\n }\n }\n\n onFileMinified();\n }\n );\n } else {\n // Route any other modules straight through\n const cached: CachedSource = new CachedSource(\n postProcessCode(new ReplaceSource(source), {\n compilation,\n module: mod,\n loggingName: mod.identifier()\n })\n );\n\n const minifiedSize: number = Buffer.byteLength(cached.source(), 'utf-8');\n mod.factoryMeta.minifiedSize = minifiedSize;\n\n minifiedModules.set(realId !== undefined ? realId : id, {\n source: cached,\n module: mod\n });\n }\n }\n\n // Return something so that this stage still produces valid ECMAScript\n return new RawSource('(function(){})');\n }\n\n const jsTemplate: IExtendedModuleTemplate = compilation.moduleTemplates\n .javascript as IExtendedModuleTemplate;\n const innerRender: IExtendedModuleTemplate['render'] = jsTemplate.render.bind(jsTemplate);\n\n // The optimizeTree hook is the last async hook that occurs before chunk rendering\n compilation.hooks.optimizeTree.tapPromise(PLUGIN_NAME, async () => {\n minifierConnection = await minifier.connect();\n\n submittedModules.clear();\n\n const cache: WeakSet<IExtendedModule> = new WeakSet();\n const defaultSource: Source = new RawSource('');\n\n // During code generation, send the generated code to the minifier and replace with a placeholder\n // Hacking this to avoid calling .source() on a concatenated module multiple times\n jsTemplate.render = (module: IExtendedModule, dependencyTemplates, options) => {\n if (!cache.has(module)) {\n cache.add(module);\n const rendered: Source = innerRender(module, dependencyTemplates, options);\n\n minifyModule(rendered, module);\n }\n\n return defaultSource;\n };\n });\n\n // This should happen before any other tasks that operate during optimizeChunkAssets\n compilation.hooks.optimizeChunkAssets.tapPromise(\n TAP_BEFORE,\n async (chunks: webpack.compilation.Chunk[]): Promise<void> => {\n // Still need to minify the rendered assets\n for (const chunk of chunks) {\n const externals: string[] = [];\n const externalNames: Map<string, string> = new Map();\n\n const chunkModuleSet: Set<string | number> = new Set();\n const allChunkModules: Iterable<IExtendedModule> =\n chunk.modulesIterable as Iterable<IExtendedModule>;\n let hasNonNumber: boolean = false;\n for (const mod of allChunkModules) {\n if (mod.id !== null) {\n if (typeof mod.id !== 'number') {\n hasNonNumber = true;\n }\n chunkModuleSet.add(mod.id);\n\n if (mod.external) {\n // Match the identifiers generated in the AmdMainTemplatePlugin\n // https://github.com/webpack/webpack/blob/444e59f8a427f94f0064cae6765e5a3c4b78596d/lib/AmdMainTemplatePlugin.js#L49\n const key: string = `__WEBPACK_EXTERNAL_MODULE_${webpack.Template.toIdentifier(\n `${mod.id}`\n )}__`;\n // The first two identifiers are used for function (module, exports) at the module site\n const ordinal: number = 2 + externals.length;\n const miniId: string = getIdentifier(ordinal);\n externals.push(key);\n externalNames.set(key, miniId);\n }\n }\n }\n\n const chunkModules: (string | number)[] = Array.from(chunkModuleSet);\n // Sort by id before rehydration in case we rehydrate a given chunk multiple times\n chunkModules.sort(\n hasNonNumber\n ? stringifyIdSortPredicate\n : (x: string | number, y: string | number) => (x as number) - (y as number)\n );\n\n for (const assetName of chunk.files) {\n const asset: Source = compilation.assets[assetName];\n\n // Verify that this is a JS asset\n if (/\\.m?js(\\?.+)?$/.test(assetName)) {\n ++pendingMinificationRequests;\n\n const rawCode: string = asset.source() as string;\n const nameForMap: string = `(chunks)/${assetName}`;\n\n const hash: string = hashCodeFragment(rawCode);\n\n minifier.minify(\n {\n hash,\n code: rawCode,\n nameForMap: useSourceMaps ? nameForMap : undefined,\n externals\n },\n (result: IModuleMinificationResult) => {\n if (isMinificationResultError(result)) {\n compilation.errors.push(result.error);\n console.error(result.error);\n } else {\n try {\n const { code: minified, map: minifierMap } = result;\n\n let codeForMap: string = rawCode;\n if (useSourceMaps) {\n // Pretend the __WEBPACK_CHUNK_MODULES__ token is an array of module ids, so that the source map contains information about the module ids in the chunk\n codeForMap = codeForMap.replace(\n CHUNK_MODULES_TOKEN,\n JSON.stringify(chunkModules, undefined, 2)\n );\n }\n\n const rawOutput: Source = useSourceMaps\n ? new SourceMapSource(\n minified, // Code\n nameForMap, // File\n minifierMap!, // Base source map\n codeForMap, // Source from before transform\n undefined, // Source Map from before transform\n false // Remove original source\n )\n : new RawSource(minified);\n\n const withIds: Source = postProcessCode(new ReplaceSource(rawOutput), {\n compilation,\n module: undefined,\n loggingName: assetName\n });\n\n minifiedAssets.set(assetName, {\n source: new CachedSource(withIds),\n modules: chunkModules,\n chunk,\n fileName: assetName,\n renderInfo: new Map(),\n externalNames\n });\n } catch (err) {\n compilation.errors.push(err);\n }\n }\n\n onFileMinified();\n }\n );\n } else {\n // This isn't a JS asset. Don't try to minify the asset wrapper, though if it contains modules, those might still get replaced with minified versions.\n minifiedAssets.set(assetName, {\n // Still need to restore ids\n source: postProcessCode(new ReplaceSource(asset), {\n compilation,\n module: undefined,\n loggingName: assetName\n }),\n modules: chunkModules,\n chunk,\n fileName: assetName,\n renderInfo: new Map(),\n externalNames\n });\n }\n }\n }\n\n allRequestsIssued = true;\n\n if (pendingMinificationRequests) {\n await new Promise<void>((resolve) => {\n resolveMinifyPromise = resolve;\n });\n }\n\n // Handle any error from the minifier.\n await minifierConnection?.disconnect();\n\n // All assets and modules have been minified, hand them off to be rehydrated\n await this.hooks.rehydrateAssets.promise(\n {\n assets: minifiedAssets,\n modules: minifiedModules\n },\n compilation\n );\n }\n );\n\n function updateChunkHash(hash: Hash, chunk: webpack.compilation.Chunk): void {\n // Apply the options hash\n hash.update(binaryConfig);\n // Apply the hash from the minifier\n if (minifierConnection) {\n hash.update(minifierConnection.configHash, 'utf8');\n }\n }\n\n // Need to update chunk hashes with information from this plugin\n (compilation.chunkTemplate as unknown as IExtendedChunkTemplate).hooks.hashForChunk.tap(\n PLUGIN_NAME,\n updateChunkHash\n );\n compilation.mainTemplate.hooks.hashForChunk.tap(PLUGIN_NAME, updateChunkHash);\n\n // This function is written twice because the parameter order is not the same between the two hooks\n (compilation.chunkTemplate as unknown as IExtendedChunkTemplate).hooks.modules.tap(\n TAP_AFTER,\n (source: Source, chunk: webpack.compilation.Chunk, moduleTemplate: unknown) => {\n if (moduleTemplate !== compilation.moduleTemplates.javascript) {\n // This is not a JavaScript asset\n return source;\n }\n\n // Discard the rendered modules\n return new RawSource(CHUNK_MODULES_TOKEN);\n }\n );\n\n (compilation.mainTemplate as unknown as IExtendedChunkTemplate).hooks.modules.tap(\n TAP_AFTER,\n (source: Source, chunk: webpack.compilation.Chunk, hash: unknown, moduleTemplate: unknown) => {\n if (moduleTemplate !== compilation.moduleTemplates.javascript) {\n // This is not a JavaScript asset\n return source;\n }\n\n // Discard the rendered modules\n return new RawSource(CHUNK_MODULES_TOKEN);\n }\n );\n }\n );\n }\n}\n"]}
|
|
@@ -2,6 +2,20 @@ import type { IModuleMinifier } from '@rushstack/module-minifier';
|
|
|
2
2
|
import type { AsyncSeriesWaterfallHook, SyncWaterfallHook } from 'tapable';
|
|
3
3
|
import type * as webpack from 'webpack';
|
|
4
4
|
import type { ReplaceSource, Source } from 'webpack-sources';
|
|
5
|
+
/**
|
|
6
|
+
* Information about where the module was rendered in the emitted asset.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface IRenderedModulePosition {
|
|
10
|
+
/**
|
|
11
|
+
* The offset from the start of tha asset to the start of the module, in characters.
|
|
12
|
+
*/
|
|
13
|
+
charOffset: number;
|
|
14
|
+
/**
|
|
15
|
+
* The length of the rendered module, in characters.
|
|
16
|
+
*/
|
|
17
|
+
charLength: number;
|
|
18
|
+
}
|
|
5
19
|
/**
|
|
6
20
|
* Information about a dehydrated webpack ECMAScript asset
|
|
7
21
|
* @public
|
|
@@ -19,6 +33,10 @@ export interface IAssetInfo {
|
|
|
19
33
|
* The ids of the modules that are part of the chunk corresponding to this asset
|
|
20
34
|
*/
|
|
21
35
|
modules: (string | number)[];
|
|
36
|
+
/**
|
|
37
|
+
* Information about the offsets and character lengths for each rendered module in the final asset.
|
|
38
|
+
*/
|
|
39
|
+
renderInfo: Map<string | number, IRenderedModulePosition>;
|
|
22
40
|
/**
|
|
23
41
|
* The raw chunk object from Webpack, in case information from it is necessary for reconstruction
|
|
24
42
|
*/
|
|
@@ -28,6 +46,20 @@ export interface IAssetInfo {
|
|
|
28
46
|
*/
|
|
29
47
|
externalNames: Map<string, string>;
|
|
30
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Statistics from the plugin. Namely module sizes.
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export interface IModuleMinifierPluginStats {
|
|
54
|
+
metadataByAssetFileName: Map<string, IAssetStats>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Rendered positional data
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
export interface IAssetStats {
|
|
61
|
+
positionByModuleId: Map<string | number, IRenderedModulePosition>;
|
|
62
|
+
}
|
|
31
63
|
/**
|
|
32
64
|
* Information about a minified module
|
|
33
65
|
* @public
|
|
@@ -1 +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;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAE7B;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC;IAEjC;;OAEG;IACH,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,EAAE,eAAe,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,OAAO,CAAC,WAAW,CAAC,MAAM;IACjE;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,OAAO,CAAC,EAA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";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"]}
|
|
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 where the module was rendered in the emitted asset.\n * @public\n */\nexport interface IRenderedModulePosition {\n /**\n * The offset from the start of tha asset to the start of the module, in characters.\n */\n charOffset: number;\n /**\n * The length of the rendered module, in characters.\n */\n charLength: number;\n}\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 * Information about the offsets and character lengths for each rendered module in the final asset.\n */\n renderInfo: Map<string | number, IRenderedModulePosition>;\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 * Statistics from the plugin. Namely module sizes.\n * @public\n */\nexport interface IModuleMinifierPluginStats {\n metadataByAssetFileName: Map<string, IAssetStats>;\n}\n\n/**\n * Rendered positional data\n * @public\n */\nexport interface IAssetStats {\n positionByModuleId: Map<string | number, IRenderedModulePosition>;\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"]}
|
package/lib/RehydrateAsset.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ import { IAssetInfo, IModuleMap } from './ModuleMinifierPlugin.types';
|
|
|
5
5
|
* @param asset - The asset
|
|
6
6
|
* @param moduleMap - The minified modules
|
|
7
7
|
* @param banner - A banner to inject for license information
|
|
8
|
+
* @param emitRenderInfo - If set, provide information about module offsets
|
|
8
9
|
* @public
|
|
9
10
|
*/
|
|
10
|
-
export declare function rehydrateAsset(asset: IAssetInfo, moduleMap: IModuleMap, banner: string): Source;
|
|
11
|
+
export declare function rehydrateAsset(asset: IAssetInfo, moduleMap: IModuleMap, banner: string, emitRenderInfo?: boolean): Source;
|
|
11
12
|
//# sourceMappingURL=RehydrateAsset.d.ts.map
|
|
@@ -1 +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
|
|
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;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,UAAU,EACjB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,MAAM,EACd,cAAc,CAAC,EAAE,OAAO,GACvB,MAAM,CAoKR"}
|
package/lib/RehydrateAsset.js
CHANGED
|
@@ -10,9 +10,10 @@ const Constants_1 = require("./Constants");
|
|
|
10
10
|
* @param asset - The asset
|
|
11
11
|
* @param moduleMap - The minified modules
|
|
12
12
|
* @param banner - A banner to inject for license information
|
|
13
|
+
* @param emitRenderInfo - If set, provide information about module offsets
|
|
13
14
|
* @public
|
|
14
15
|
*/
|
|
15
|
-
function rehydrateAsset(asset, moduleMap, banner) {
|
|
16
|
+
function rehydrateAsset(asset, moduleMap, banner, emitRenderInfo) {
|
|
16
17
|
const { source: assetSource, modules } = asset;
|
|
17
18
|
const assetCode = assetSource.source();
|
|
18
19
|
const tokenIndex = assetCode.indexOf(Constants_1.CHUNK_MODULES_TOKEN);
|
|
@@ -33,6 +34,7 @@ function rehydrateAsset(asset, moduleMap, banner) {
|
|
|
33
34
|
// This must not have the global flag set
|
|
34
35
|
const validIdRegex = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
35
36
|
const source = new webpack_sources_1.ConcatSource(banner, prefix);
|
|
37
|
+
let charOffset = source.size();
|
|
36
38
|
const firstModuleId = modules[0];
|
|
37
39
|
const lastModuleId = modules[modules.length - 1];
|
|
38
40
|
// Extended logic from webpack.Template.getModulesArrayBounds
|
|
@@ -72,11 +74,21 @@ function rehydrateAsset(asset, moduleMap, banner) {
|
|
|
72
74
|
for (const id of modules) {
|
|
73
75
|
// If the id is legal to use as a key in a JavaScript object literal, use as-is
|
|
74
76
|
const javascriptId = typeof id !== 'string' || validIdRegex.test(id) ? id : JSON.stringify(id);
|
|
75
|
-
|
|
77
|
+
const currentSeparator = `${separator}${javascriptId}:`;
|
|
78
|
+
source.add(currentSeparator);
|
|
79
|
+
charOffset += currentSeparator.length;
|
|
76
80
|
separator = ',';
|
|
77
81
|
const item = moduleMap.get(id);
|
|
78
82
|
const moduleCode = item ? item.source : emptyFunction;
|
|
83
|
+
const charLength = typeof moduleCode === 'string' ? moduleCode.length : moduleCode.size();
|
|
84
|
+
if (emitRenderInfo) {
|
|
85
|
+
asset.renderInfo.set(id, {
|
|
86
|
+
charOffset,
|
|
87
|
+
charLength
|
|
88
|
+
});
|
|
89
|
+
}
|
|
79
90
|
source.add(moduleCode);
|
|
91
|
+
charOffset += charLength;
|
|
80
92
|
}
|
|
81
93
|
source.add('}');
|
|
82
94
|
}
|
|
@@ -96,20 +108,34 @@ function rehydrateAsset(asset, moduleMap, banner) {
|
|
|
96
108
|
const fillerArrayThreshold = 11 + deltaStr.length;
|
|
97
109
|
const item = moduleMap.get(id);
|
|
98
110
|
const moduleCode = item ? item.source : emptyFunction;
|
|
111
|
+
const charLength = typeof moduleCode === 'string' ? moduleCode.length : moduleCode.size();
|
|
99
112
|
if (useConcat && delta + 1 > fillerArrayThreshold) {
|
|
100
113
|
if (concatInserted) {
|
|
101
|
-
|
|
114
|
+
const currentSeparator = `],Array(${deltaStr}),[`;
|
|
115
|
+
source.add(currentSeparator);
|
|
116
|
+
charOffset += currentSeparator.length;
|
|
102
117
|
}
|
|
103
118
|
else {
|
|
104
|
-
|
|
119
|
+
const currentSeparator = `].concat(Array(${deltaStr}),[`;
|
|
105
120
|
concatInserted = true;
|
|
121
|
+
source.add(currentSeparator);
|
|
122
|
+
charOffset += currentSeparator.length;
|
|
106
123
|
}
|
|
107
124
|
}
|
|
108
125
|
else {
|
|
109
|
-
|
|
126
|
+
const currentSeparator = separator + enoughCommas.slice(0, delta + 1);
|
|
127
|
+
source.add(currentSeparator);
|
|
128
|
+
charOffset += currentSeparator.length;
|
|
110
129
|
}
|
|
111
130
|
lastId = id;
|
|
131
|
+
if (emitRenderInfo) {
|
|
132
|
+
asset.renderInfo.set(id, {
|
|
133
|
+
charOffset,
|
|
134
|
+
charLength
|
|
135
|
+
});
|
|
136
|
+
}
|
|
112
137
|
source.add(moduleCode);
|
|
138
|
+
charOffset += charLength;
|
|
113
139
|
separator = '';
|
|
114
140
|
}
|
|
115
141
|
source.add(useConcat ? '])' : ']');
|
|
@@ -1 +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,eAA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AC,GAAG,CAAC,EAAE,CAAC,CAAC;YAEzD,IAAI,MAAM,KAAK,SAAS,EAAE;gBACxB,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,OAAO,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC;aAC5E;iBAAM;gBACL,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,eAAe,CAAC,SAAS,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;aAC3E;SACF;QAED,OAAO,IAAI,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"]}
|
|
1
|
+
{"version":3,"file":"RehydrateAsset.js","sourceRoot":"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QAE5E,mEAAmE;QACnE,IAAI,KAAK,GAA2B,IAAI,CAAC;QACzC,OAAO,CAAC,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE;YAC3C,MAAM,EAAE,GAAW,KAAK,CAAC,CAAC,CAAC,CAAC;YAC5B,MAAM,MAAM,GAAuB,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAEzD,IAAI,MAAM,KAAK,SAAS,EAAE;gBACxB,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,OAAO,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC;aAC5E;iBAAM;gBACL,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,eAAe,CAAC,SAAS,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;aAC3E;SACF;QAED,OAAO,IAAI,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 * @param emitRenderInfo - If set, provide information about module offsets\n * @public\n */\nexport function rehydrateAsset(\n asset: IAssetInfo,\n moduleMap: IModuleMap,\n banner: string,\n emitRenderInfo?: boolean\n): 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 let charOffset: number = source.size();\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 const currentSeparator: string = `${separator}${javascriptId}:`;\n\n source.add(currentSeparator);\n charOffset += currentSeparator.length;\n\n separator = ',';\n\n const item: IModuleInfo | undefined = moduleMap.get(id);\n const moduleCode: Source | string = item ? item.source : emptyFunction;\n const charLength: number = typeof moduleCode === 'string' ? moduleCode.length : moduleCode.size();\n\n if (emitRenderInfo) {\n asset.renderInfo.set(id, {\n charOffset,\n charLength\n });\n }\n\n source.add(moduleCode);\n charOffset += charLength;\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 const charLength: number = typeof moduleCode === 'string' ? moduleCode.length : moduleCode.size();\n\n if (useConcat && delta + 1 > fillerArrayThreshold) {\n if (concatInserted) {\n const currentSeparator: string = `],Array(${deltaStr}),[`;\n\n source.add(currentSeparator);\n charOffset += currentSeparator.length;\n } else {\n const currentSeparator: string = `].concat(Array(${deltaStr}),[`;\n concatInserted = true;\n\n source.add(currentSeparator);\n charOffset += currentSeparator.length;\n }\n } else {\n const currentSeparator: string = separator + enoughCommas.slice(0, delta + 1);\n\n source.add(currentSeparator);\n charOffset += currentSeparator.length;\n }\n lastId = id as number;\n\n if (emitRenderInfo) {\n asset.renderInfo.set(id, {\n charOffset,\n charLength\n });\n }\n\n source.add(moduleCode);\n charOffset += charLength;\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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/webpack4-module-minifier-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "This plugin splits minification of webpack compilations into smaller units.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "dist/webpack4-module-minifier-plugin.d.ts",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@types/tapable": "1.0.6",
|
|
36
36
|
"tapable": "1.1.3",
|
|
37
|
-
"@rushstack/module-minifier": "0.3.
|
|
38
|
-
"@rushstack/worker-pool": "0.3.
|
|
37
|
+
"@rushstack/module-minifier": "0.3.5",
|
|
38
|
+
"@rushstack/worker-pool": "0.3.5"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/heft-jest": "1.0.1",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"webpack": "~4.44.2",
|
|
46
46
|
"webpack-sources": "~1.4.3",
|
|
47
47
|
"@rushstack/eslint-config": "3.2.0",
|
|
48
|
-
"@rushstack/heft": "0.50.
|
|
49
|
-
"@rushstack/heft-node-rig": "1.12.
|
|
48
|
+
"@rushstack/heft": "0.50.1",
|
|
49
|
+
"@rushstack/heft-node-rig": "1.12.7"
|
|
50
50
|
},
|
|
51
51
|
"sideEffects": [
|
|
52
52
|
"./lib/OverrideWebpackIdentifierAllocation"
|