@rushstack/webpack4-module-minifier-plugin 0.12.28 → 0.12.30

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.
@@ -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;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,UAAU,EACjB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,MAAM,EACd,cAAc,CAAC,EAAE,OAAO,GACvB,MAAM,CAoKR"}
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,CAyKR"}
@@ -34,7 +34,8 @@ function rehydrateAsset(asset, moduleMap, banner, emitRenderInfo) {
34
34
  // This must not have the global flag set
35
35
  const validIdRegex = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
36
36
  const source = new webpack_sources_1.ConcatSource(banner, prefix);
37
- let charOffset = source.size();
37
+ // Source.size() is in bytes, we want characters
38
+ let charOffset = source.source().length;
38
39
  const firstModuleId = modules[0];
39
40
  const lastModuleId = modules[modules.length - 1];
40
41
  // Extended logic from webpack.Template.getModulesArrayBounds
@@ -80,7 +81,8 @@ function rehydrateAsset(asset, moduleMap, banner, emitRenderInfo) {
80
81
  separator = ',';
81
82
  const item = moduleMap.get(id);
82
83
  const moduleCode = item ? item.source : emptyFunction;
83
- const charLength = typeof moduleCode === 'string' ? moduleCode.length : moduleCode.size();
84
+ // Source.size() is in bytes, we want characters
85
+ const charLength = typeof moduleCode === 'string' ? moduleCode.length : moduleCode.source().toString().length;
84
86
  if (emitRenderInfo) {
85
87
  asset.renderInfo.set(id, {
86
88
  charOffset,
@@ -108,7 +110,8 @@ function rehydrateAsset(asset, moduleMap, banner, emitRenderInfo) {
108
110
  const fillerArrayThreshold = 11 + deltaStr.length;
109
111
  const item = moduleMap.get(id);
110
112
  const moduleCode = item ? item.source : emptyFunction;
111
- const charLength = typeof moduleCode === 'string' ? moduleCode.length : moduleCode.size();
113
+ // Source.size() is in bytes, we want characters
114
+ const charLength = typeof moduleCode === 'string' ? moduleCode.length : moduleCode.source().toString().length;
112
115
  if (useConcat && delta + 1 > fillerArrayThreshold) {
113
116
  if (concatInserted) {
114
117
  const currentSeparator = `],Array(${deltaStr}),[`;
@@ -1 +1 @@
1
- {"version":3,"file":"RehydrateAsset.js","sourceRoot":"","sources":["../src/RehydrateAsset.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,qDAAoF;AAEpF,2CAAkD;AAGlD;;;;;;;GAOG;AACH,SAAgB,cAAc,CAC5B,KAAiB,EACjB,SAAqB,EACrB,MAAc,EACd,cAAwB;IAExB,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAE/C,MAAM,SAAS,GAAW,WAAW,CAAC,MAAM,EAAY,CAAC;IAEzD,MAAM,UAAU,GAAW,SAAS,CAAC,OAAO,CAAC,+BAAmB,CAAC,CAAC;IAClE,IAAI,UAAU,GAAG,CAAC,EAAE;QAClB,0BAA0B;QAC1B,OAAO,eAAe,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;KAC5C;IACD,MAAM,WAAW,GAAW,UAAU,GAAG,+BAA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AC,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"]}
1
+ {"version":3,"file":"RehydrateAsset.js","sourceRoot":"","sources":["../src/RehydrateAsset.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,qDAAoF;AAEpF,2CAAkD;AAGlD;;;;;;;GAOG;AACH,SAAgB,cAAc,CAC5B,KAAiB,EACjB,SAAqB,EACrB,MAAc,EACd,cAAwB;IAExB,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAE/C,MAAM,SAAS,GAAW,WAAW,CAAC,MAAM,EAAY,CAAC;IAEzD,MAAM,UAAU,GAAW,SAAS,CAAC,OAAO,CAAC,+BAAmB,CAAC,CAAC;IAClE,IAAI,UAAU,GAAG,CAAC,EAAE;QAClB,0BAA0B;QAC1B,OAAO,eAAe,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;KAC5C;IACD,MAAM,WAAW,GAAW,UAAU,GAAG,+BAAmB,CAAC,MAAM,CAAC;IACpE,MAAM,MAAM,GAAW,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAEpD,MAAM,MAAM,GAAkB,IAAI,+BAAa,CAAC,WAAW,CAAC,CAAC;IAC7D,uCAAuC;IACvC,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAEjD,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,+BAA+B;QAC/B,OAAO,IAAI,8BAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;KACvD;IAED,MAAM,aAAa,GAAG,cAAc,CAAC,CAAC,iDAAiD;IACvF,yCAAyC;IACzC,MAAM,YAAY,GAAW,4BAA4B,CAAC;IAE1D,MA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wCA8KC;AAED,SAAS,eAAe,CAAC,MAAc,EAAE,KAAiB;IACxD,MAAM,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC;IAEhC,IAAI,aAAa,CAAC,IAAI,EAAE;QACtB,MAAM,aAAa,GAAkB,IAAI,+BAAa,CAAC,MAAM,CAAC,CAAC;QAC/D,MAAM,IAAI,GAAW,MAAM,CAAC,MAAM,EAAY,CAAC;QAE/C,MAAM,eAAe,GAAW,2CAA2C,CAAC;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 // Source.size() is in bytes, we want characters\n let charOffset: number = source.source().length;\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 // Source.size() is in bytes, we want characters\n const charLength: number =\n typeof moduleCode === 'string' ? moduleCode.length : moduleCode.source().toString().length;\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 // Source.size() is in bytes, we want characters\n const charLength: number =\n typeof moduleCode === 'string' ? moduleCode.length : moduleCode.source().toString().length;\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.12.28",
3
+ "version": "0.12.30",
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.32",
38
- "@rushstack/worker-pool": "0.3.31"
37
+ "@rushstack/module-minifier": "0.3.34",
38
+ "@rushstack/worker-pool": "0.3.33"
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.3.2",
48
- "@rushstack/heft": "0.57.0",
49
- "@rushstack/heft-node-rig": "2.2.16"
48
+ "@rushstack/heft": "0.57.1",
49
+ "@rushstack/heft-node-rig": "2.2.18"
50
50
  },
51
51
  "sideEffects": [
52
52
  "./lib/OverrideWebpackIdentifierAllocation"