-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13113 from webpack/bugfix/define-caching
DefinePlugin invalidates modules when new defines are added
- Loading branch information
Showing
13 changed files
with
135 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default [DEFINE.A, RUN]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default [DEFINE.B, RUN]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default [DEFINE.C, RUN]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import a from "./a"; | ||
import b from "./b"; | ||
import c from "./c"; | ||
|
||
it("should invalidate modules when properties are added/removed from the DefinePlugin", () => { | ||
expect(a).toEqual([0, 0]); | ||
expect(b).toEqual([2, 0]); | ||
expect(c).toEqual([undefined, 0]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import a from "./a"; | ||
import b from "./b"; | ||
import c from "./c"; | ||
|
||
it("should invalidate modules when properties are added/removed from the DefinePlugin", () => { | ||
expect(a).toEqual([1, 1]); | ||
expect(b).toEqual([2, 0]); | ||
expect(c).toEqual([undefined, 0]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import a from "./a"; | ||
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(b).toEqual([2, 2]); | ||
expect(c).toEqual([3, 2]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import a from "./a"; | ||
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(b).toEqual([undefined, 3]); | ||
expect(c).toEqual([3, 2]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const { DefinePlugin } = require("../../../../"); | ||
|
||
/** @type {import("../../../../").Configuration} */ | ||
module.exports = { | ||
cache: { | ||
type: "memory" | ||
}, | ||
plugins: [ | ||
compiler => { | ||
const base = { | ||
DEFINE: "{}", | ||
RUN: DefinePlugin.runtimeValue(() => 3 - defines.length, []) | ||
}; | ||
const defines = [ | ||
{ | ||
...base, | ||
"DEFINE.A": 0, | ||
"DEFINE.B": 2 | ||
}, | ||
{ | ||
// change | ||
...base, | ||
"DEFINE.A": 1, | ||
"DEFINE.B": 2 | ||
}, | ||
{ | ||
// add | ||
...base, | ||
"DEFINE.A": 1, | ||
"DEFINE.B": 2, | ||
"DEFINE.C": 3 | ||
}, | ||
{ | ||
// remove | ||
...base, | ||
"DEFINE.A": 1, | ||
"DEFINE.C": 3 | ||
} | ||
]; | ||
compiler.hooks.compilation.tap("webpack.config", (...args) => { | ||
const plugin = new DefinePlugin(defines.shift()); | ||
plugin.apply( | ||
/** @type {any} */ ({ | ||
hooks: { | ||
compilation: { | ||
tap: (name, fn) => { | ||
fn(...args); | ||
} | ||
} | ||
} | ||
}) | ||
); | ||
}); | ||
} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters