Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix problem that modules were removed before they were flagged as used fixes #10189 backport of #10205 fixes #10475
- Loading branch information
Showing
22 changed files
with
175 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
MIT License http://www.opensource.org/licenses/mit-license.php | ||
Author Tobias Koppers @sokra | ||
*/ | ||
|
||
"use strict"; | ||
|
||
/** @typedef {import("./Compiler")} Compiler */ | ||
|
||
class FlagAllModulesAsUsedPlugin { | ||
constructor(explanation) { | ||
this.explanation = explanation; | ||
} | ||
|
||
/** | ||
* @param {Compiler} compiler webpack compiler | ||
* @returns {void} | ||
*/ | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap( | ||
"FlagAllModulesAsUsedPlugin", | ||
compilation => { | ||
compilation.hooks.optimizeDependencies.tap( | ||
"FlagAllModulesAsUsedPlugin", | ||
modules => { | ||
for (const module of modules) { | ||
module.used = true; | ||
module.usedExports = true; | ||
module.addReason(null, null, this.explanation); | ||
} | ||
} | ||
); | ||
} | ||
); | ||
} | ||
} | ||
|
||
module.exports = FlagAllModulesAsUsedPlugin; |
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
3 changes: 3 additions & 0 deletions
3
test/configCases/dll-plugin-side-effects/0-create-dll/dependency.js
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,3 @@ | ||
export default function createB() { | ||
return "b"; | ||
} |
3 changes: 3 additions & 0 deletions
3
test/configCases/dll-plugin-side-effects/0-create-dll/dependency2.js
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,3 @@ | ||
export default function createC() { | ||
return "c"; | ||
} |
3 changes: 3 additions & 0 deletions
3
test/configCases/dll-plugin-side-effects/0-create-dll/index.js
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,3 @@ | ||
import { a } from "./module"; | ||
|
||
export default a(); |
12 changes: 12 additions & 0 deletions
12
test/configCases/dll-plugin-side-effects/0-create-dll/module.js
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,12 @@ | ||
import createB from "./dependency"; | ||
import createC from "./dependency2"; | ||
|
||
export function a() { | ||
return "a"; | ||
} | ||
|
||
export { createB as b }; | ||
|
||
export function c() { | ||
return createC(); | ||
} |
1 change: 1 addition & 0 deletions
1
test/configCases/dll-plugin-side-effects/0-create-dll/test.config.js
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 @@ | ||
exports.noTests = true; |
31 changes: 31 additions & 0 deletions
31
test/configCases/dll-plugin-side-effects/0-create-dll/webpack.config.js
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,31 @@ | ||
var path = require("path"); | ||
var webpack = require("../../../../"); | ||
|
||
module.exports = { | ||
entry: ["./index"], | ||
output: { | ||
filename: "dll.js", | ||
chunkFilename: "[id].dll.js", | ||
libraryTarget: "commonjs2" | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /0-create-dll.(module|dependency)/, | ||
sideEffects: false | ||
} | ||
] | ||
}, | ||
optimization: { | ||
usedExports: true, | ||
sideEffects: true | ||
}, | ||
plugins: [ | ||
new webpack.DllPlugin({ | ||
path: path.resolve( | ||
__dirname, | ||
"../../../js/config/dll-plugin-side-effects/manifest0.json" | ||
) | ||
}) | ||
] | ||
}; |
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 @@ | ||
it("should include all exports and modules in the dll", function() { | ||
const { a, b, c } = require("dll/module"); | ||
expect(typeof a).toBe("function"); | ||
expect(a()).toBe("a"); | ||
expect(typeof b).toBe("function"); | ||
expect(b()).toBe("b"); | ||
expect(typeof c).toBe("function"); | ||
expect(c()).toBe("c"); | ||
}); |
12 changes: 12 additions & 0 deletions
12
test/configCases/dll-plugin-side-effects/1-use-dll/webpack.config.js
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,12 @@ | ||
var webpack = require("../../../../"); | ||
|
||
module.exports = { | ||
plugins: [ | ||
new webpack.DllReferencePlugin({ | ||
manifest: require("../../../js/config/dll-plugin-side-effects/manifest0.json"), // eslint-disable-line node/no-missing-require | ||
name: "../0-create-dll/dll.js", | ||
scope: "dll", | ||
sourceType: "commonjs2" | ||
}) | ||
] | ||
}; |
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 |
---|---|---|
|
@@ -27,6 +27,7 @@ module.exports = { | |
] | ||
}, | ||
optimization: { | ||
usedExports: true, | ||
sideEffects: true | ||
}, | ||
plugins: [ | ||
|
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,3 @@ | ||
import { constants } from "test-package"; | ||
|
||
var x = constants; |
2 changes: 2 additions & 0 deletions
2
test/configCases/dll-plugin/0-issue-10475/node_modules/test-package/constants.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
test/configCases/dll-plugin/0-issue-10475/node_modules/test-package/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
test/configCases/dll-plugin/0-issue-10475/node_modules/test-package/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
test/configCases/dll-plugin/0-issue-10475/node_modules/test-package/someFunction.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
test/configCases/dll-plugin/0-issue-10475/node_modules/test-package/working-constants.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
exports.noTests = true; |
19 changes: 19 additions & 0 deletions
19
test/configCases/dll-plugin/0-issue-10475/webpack.config.js
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,19 @@ | ||
var path = require("path"); | ||
var webpack = require("../../../../"); | ||
|
||
module.exports = { | ||
entry: ["./index.js"], | ||
output: { | ||
filename: "dll.js", | ||
chunkFilename: "[id].dll.js", | ||
libraryTarget: "commonjs2" | ||
}, | ||
plugins: [ | ||
new webpack.DllPlugin({ | ||
path: path.resolve( | ||
__dirname, | ||
"../../../js/config/dll-plugin/issue-10475.json" | ||
) | ||
}) | ||
] | ||
}; |
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,3 @@ | ||
it("should have all modules", () => { | ||
require("dll/index.js"); | ||
}); |
12 changes: 12 additions & 0 deletions
12
test/configCases/dll-plugin/1-issue-10475/webpack.config.js
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,12 @@ | ||
var webpack = require("../../../../"); | ||
|
||
module.exports = { | ||
plugins: [ | ||
new webpack.DllReferencePlugin({ | ||
manifest: require("../../../js/config/dll-plugin/issue-10475.json"), // eslint-disable-line node/no-missing-require | ||
name: "../0-issue-10475/dll.js", | ||
scope: "dll", | ||
sourceType: "commonjs2" | ||
}) | ||
] | ||
}; |