mirror of https://github.com/webpack/webpack.git
refactor: code
This commit is contained in:
parent
1b217a6d94
commit
0011ec130a
|
@ -53,7 +53,6 @@ const DefaultStatsFactoryPlugin = require("./stats/DefaultStatsFactoryPlugin");
|
||||||
const DefaultStatsPresetPlugin = require("./stats/DefaultStatsPresetPlugin");
|
const DefaultStatsPresetPlugin = require("./stats/DefaultStatsPresetPlugin");
|
||||||
const DefaultStatsPrinterPlugin = require("./stats/DefaultStatsPrinterPlugin");
|
const DefaultStatsPrinterPlugin = require("./stats/DefaultStatsPrinterPlugin");
|
||||||
|
|
||||||
const { STAGE_BASIC, STAGE_ADVANCED } = require("./OptimizationStages");
|
|
||||||
const { cleverMerge } = require("./util/cleverMerge");
|
const { cleverMerge } = require("./util/cleverMerge");
|
||||||
|
|
||||||
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
||||||
|
@ -433,10 +432,6 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
const RemoveEmptyChunksPlugin = require("./optimize/RemoveEmptyChunksPlugin");
|
const RemoveEmptyChunksPlugin = require("./optimize/RemoveEmptyChunksPlugin");
|
||||||
new RemoveEmptyChunksPlugin().apply(compiler);
|
new RemoveEmptyChunksPlugin().apply(compiler);
|
||||||
}
|
}
|
||||||
if (options.optimization.mergeDuplicateChunks) {
|
|
||||||
const MergeDuplicateChunksPlugin = require("./optimize/MergeDuplicateChunksPlugin");
|
|
||||||
new MergeDuplicateChunksPlugin(STAGE_BASIC).apply(compiler);
|
|
||||||
}
|
|
||||||
if (options.optimization.flagIncludedChunks) {
|
if (options.optimization.flagIncludedChunks) {
|
||||||
const FlagIncludedChunksPlugin = require("./optimize/FlagIncludedChunksPlugin");
|
const FlagIncludedChunksPlugin = require("./optimize/FlagIncludedChunksPlugin");
|
||||||
new FlagIncludedChunksPlugin().apply(compiler);
|
new FlagIncludedChunksPlugin().apply(compiler);
|
||||||
|
@ -476,8 +471,8 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
new SplitChunksPlugin(options.optimization.splitChunks).apply(compiler);
|
new SplitChunksPlugin(options.optimization.splitChunks).apply(compiler);
|
||||||
}
|
}
|
||||||
if (options.optimization.mergeDuplicateChunks) {
|
if (options.optimization.mergeDuplicateChunks) {
|
||||||
const MergeDuplicateChunksPluginAdv = require("./optimize/MergeDuplicateChunksPlugin");
|
const MergeDuplicateChunksPlugin = require("./optimize/MergeDuplicateChunksPlugin");
|
||||||
new MergeDuplicateChunksPluginAdv(STAGE_ADVANCED).apply(compiler);
|
new MergeDuplicateChunksPlugin().apply(compiler);
|
||||||
}
|
}
|
||||||
if (options.optimization.runtimeChunk) {
|
if (options.optimization.runtimeChunk) {
|
||||||
const RuntimeChunkPlugin = require("./optimize/RuntimeChunkPlugin");
|
const RuntimeChunkPlugin = require("./optimize/RuntimeChunkPlugin");
|
||||||
|
|
|
@ -5,15 +5,12 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const { STAGE_ADVANCED } = require("../OptimizationStages");
|
||||||
const { runtimeEqual } = require("../util/runtime");
|
const { runtimeEqual } = require("../util/runtime");
|
||||||
|
|
||||||
/** @typedef {import("../Compiler")} Compiler */
|
/** @typedef {import("../Compiler")} Compiler */
|
||||||
|
|
||||||
class MergeDuplicateChunksPlugin {
|
class MergeDuplicateChunksPlugin {
|
||||||
constructor(stage) {
|
|
||||||
this.stage = stage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Compiler} compiler the compiler
|
* @param {Compiler} compiler the compiler
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
|
@ -25,7 +22,7 @@ class MergeDuplicateChunksPlugin {
|
||||||
compilation.hooks.optimizeChunks.tap(
|
compilation.hooks.optimizeChunks.tap(
|
||||||
{
|
{
|
||||||
name: "MergeDuplicateChunksPlugin",
|
name: "MergeDuplicateChunksPlugin",
|
||||||
stage: this.stage
|
stage: STAGE_ADVANCED
|
||||||
},
|
},
|
||||||
chunks => {
|
chunks => {
|
||||||
const { chunkGraph, moduleGraph } = compilation;
|
const { chunkGraph, moduleGraph } = compilation;
|
||||||
|
|
|
@ -4097,6 +4097,29 @@ chunk (runtime: main) 914.js X bytes <{792}> ={60}= ={263}= [rendered] split chu
|
||||||
webpack x.x.x compiled successfully"
|
webpack x.x.x compiled successfully"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`StatsTestCases should print correct stats for split-chunks-dedup 1`] = `
|
||||||
|
"asset main.js X KiB [emitted] (name: main) (id hint: main)
|
||||||
|
asset table-643--shared.js X bytes [emitted]
|
||||||
|
asset row-359--shared.js X bytes [emitted]
|
||||||
|
asset cell--shared.js X bytes [emitted]
|
||||||
|
asset templater--shared.js X bytes [emitted]
|
||||||
|
runtime modules X KiB 11 modules
|
||||||
|
built modules X bytes (javascript) X bytes (share-init) X bytes (consume-shared) [built]
|
||||||
|
cacheable modules X bytes
|
||||||
|
modules by path ./node_modules/ X bytes 4 modules
|
||||||
|
modules by path ./*.js X bytes 2 modules
|
||||||
|
provide-module modules X bytes
|
||||||
|
provide shared module (default) cell@1.0.0 = ./node_modules/cell/index.js X bytes [built] [code generated]
|
||||||
|
provide shared module (default) row@1.0.0 = ./node_modules/row/index.js X bytes [built] [code generated]
|
||||||
|
+ 2 modules
|
||||||
|
consume-shared-module modules X bytes
|
||||||
|
consume shared module (default) table@=1.0.0 (strict) (fallback: ./node_modules/...(truncated) X bytes [built] [code generated]
|
||||||
|
consume shared module (default) row@=1.0.0 (strict) (fallback: ./node_modules...(truncated) X bytes [built] [code generated]
|
||||||
|
consume shared module (default) templater@=1.0.0 (strict) (fallback: ./node_modu...(truncated) X bytes [built] [code generated]
|
||||||
|
consume shared module (default) cell@=1.0.0 (strict) (fallback: ./node_modules/...(truncated) X bytes [built] [code generated]
|
||||||
|
webpack x.x.x compiled successfully in X ms"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`StatsTestCases should print correct stats for split-chunks-issue-6413 1`] = `
|
exports[`StatsTestCases should print correct stats for split-chunks-issue-6413 1`] = `
|
||||||
"Entrypoint main X KiB = main.js
|
"Entrypoint main X KiB = main.js
|
||||||
chunk (runtime: main) async-b.js (async-b) X bytes <{792}> ={476}= ={628}= [rendered]
|
chunk (runtime: main) async-b.js (async-b) X bytes <{792}> ={476}= ={628}= [rendered]
|
||||||
|
@ -4724,29 +4747,6 @@ global:
|
||||||
global (webpack x.x.x) compiled successfully in X ms"
|
global (webpack x.x.x) compiled successfully in X ms"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`StatsTestCases should print correct stats for split-chunks-dedup 1`] = `
|
|
||||||
"asset main.js X KiB [emitted] (name: main) (id hint: main)
|
|
||||||
asset table--shared X bytes [emitted]
|
|
||||||
asset row-359--shared X bytes [emitted]
|
|
||||||
asset cell--shared X bytes [emitted]
|
|
||||||
asset templater--shared X bytes [emitted]
|
|
||||||
runtime modules X KiB 11 modules
|
|
||||||
built modules X bytes (javascript) X bytes (share-init) X bytes (consume-shared) [built]
|
|
||||||
cacheable modules X bytes
|
|
||||||
modules by path ./node_modules/ X bytes 4 modules
|
|
||||||
modules by path ./*.js X bytes 2 modules
|
|
||||||
provide-module modules X bytes
|
|
||||||
provide shared module (default) cell@1.0.0 = ./node_modules/cell/index.js X bytes [built] [code generated]
|
|
||||||
provide shared module (default) row@1.0.0 = ./node_modules/row/index.js X bytes [built] [code generated]
|
|
||||||
+ 2 modules
|
|
||||||
consume-shared-module modules X bytes
|
|
||||||
consume shared module (default) table@=1.0.0 (strict) (fallback: ./node_modules/...(truncated) X bytes [built] [code generated]
|
|
||||||
consume shared module (default) row@=1.0.0 (strict) (fallback: ./node_modules...(truncated) X bytes [built] [code generated]
|
|
||||||
consume shared module (default) templater@=1.0.0 (strict) (fallback: ./node_modu...(truncated) X bytes [built] [code generated]
|
|
||||||
consume shared module (default) cell@=1.0.0 (strict) (fallback: ./node_modules/...(truncated) X bytes [built] [code generated]
|
|
||||||
webpack x.x.x compiled successfully in X ms"
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`StatsTestCases should print correct stats for tree-shaking 1`] = `
|
exports[`StatsTestCases should print correct stats for tree-shaking 1`] = `
|
||||||
"asset bundle.js X KiB [emitted] (name: main)
|
"asset bundle.js X KiB [emitted] (name: main)
|
||||||
runtime modules X bytes 3 modules
|
runtime modules X bytes 3 modules
|
||||||
|
|
|
@ -36,7 +36,7 @@ module.exports = {
|
||||||
chunk.id
|
chunk.id
|
||||||
) {
|
) {
|
||||||
if (chunkIdChunkNameMap.has(chunk.id)) {
|
if (chunkIdChunkNameMap.has(chunk.id)) {
|
||||||
return chunkIdChunkNameMap.get(chunk.id);
|
return `${chunkIdChunkNameMap.get(chunk.id)}.js`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
@ -49,13 +49,13 @@ module.exports = {
|
||||||
usedSharedModuleNames.add(sharedModuleName);
|
usedSharedModuleNames.add(sharedModuleName);
|
||||||
chunkIdChunkNameMap.set(chunk.id, chunkName);
|
chunkIdChunkNameMap.set(chunk.id, chunkName);
|
||||||
|
|
||||||
return chunkName;
|
return `${chunkName}.js`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "[id]--chunk";
|
return "[id]--chunk.js";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
|
Loading…
Reference in New Issue