mirror of https://github.com/webpack/webpack.git
Merge pull request #14366 from webpack/perf/define-hash
use a hash instead of a list to track DefinePlugin dependency
This commit is contained in:
commit
b7f382878e
|
|
@ -13,7 +13,7 @@ const {
|
|||
evaluateToString,
|
||||
toConstantDependency
|
||||
} = require("./javascript/JavascriptParserHelpers");
|
||||
const { provide } = require("./util/MapHelpers");
|
||||
const createHash = require("./util/createHash");
|
||||
|
||||
/** @typedef {import("estree").Expression} Expression */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
|
@ -286,12 +286,11 @@ class DefinePlugin {
|
|||
);
|
||||
const { runtimeTemplate } = compilation;
|
||||
|
||||
const mainValue = /** @type {Set<string>} */ (
|
||||
provide(
|
||||
compilation.valueCacheVersions,
|
||||
VALUE_DEP_MAIN,
|
||||
() => new Set()
|
||||
)
|
||||
const mainHash = createHash(compilation.outputOptions.hashFunction);
|
||||
mainHash.update(
|
||||
/** @type {string} */ (
|
||||
compilation.valueCacheVersions.get(VALUE_DEP_MAIN)
|
||||
) || ""
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
@ -300,6 +299,7 @@ class DefinePlugin {
|
|||
* @returns {void}
|
||||
*/
|
||||
const handler = parser => {
|
||||
const mainValue = compilation.valueCacheVersions.get(VALUE_DEP_MAIN);
|
||||
parser.hooks.program.tap("DefinePlugin", () => {
|
||||
const { buildInfo } = parser.state.module;
|
||||
if (!buildInfo.valueDependencies)
|
||||
|
|
@ -565,7 +565,7 @@ class DefinePlugin {
|
|||
const code = definitions[key];
|
||||
const version = toCacheVersion(code);
|
||||
const name = VALUE_DEP_PREFIX + prefix + key;
|
||||
mainValue.add(name);
|
||||
mainHash.update("|" + prefix + key);
|
||||
const oldVersion = compilation.valueCacheVersions.get(name);
|
||||
if (oldVersion === undefined) {
|
||||
compilation.valueCacheVersions.set(name, version);
|
||||
|
|
@ -589,6 +589,11 @@ class DefinePlugin {
|
|||
};
|
||||
|
||||
walkDefinitionsForValues(definitions, "");
|
||||
|
||||
compilation.valueCacheVersions.set(
|
||||
VALUE_DEP_MAIN,
|
||||
/** @type {string} */ (mainHash.digest("hex").slice(0, 8))
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import b from "./b";
|
|||
import c from "./c";
|
||||
|
||||
it("should invalidate modules when properties are added/removed from the DefinePlugin", () => {
|
||||
expect(a).toEqual([1, 2]);
|
||||
expect(a).toEqual([1, 3]);
|
||||
expect(b).toEqual([undefined, 3]);
|
||||
expect(c).toEqual([3, 2]);
|
||||
expect(c).toEqual([3, 3]);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue