flag all modules as used for Dll
fix problem that modules were removed before they were flagged as used fixes #10189 backport of #10205 fixes #10475
This commit is contained in:
parent
d147689836
commit
c1aa9d4506
|
@ -5,8 +5,8 @@
|
|||
"use strict";
|
||||
|
||||
const DllEntryPlugin = require("./DllEntryPlugin");
|
||||
const FlagAllModulesAsUsedPlugin = require("./FlagAllModulesAsUsedPlugin");
|
||||
const LibManifestPlugin = require("./LibManifestPlugin");
|
||||
const FlagInitialModulesAsUsedPlugin = require("./FlagInitialModulesAsUsedPlugin");
|
||||
|
||||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/DllPlugin.json");
|
||||
|
@ -41,7 +41,7 @@ class DllPlugin {
|
|||
});
|
||||
new LibManifestPlugin(this.options).apply(compiler);
|
||||
if (!this.options.entryOnly) {
|
||||
new FlagInitialModulesAsUsedPlugin("DllPlugin").apply(compiler);
|
||||
new FlagAllModulesAsUsedPlugin("DllPlugin").apply(compiler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
|
@ -93,7 +93,7 @@ class FlagDependencyUsagePlugin {
|
|||
};
|
||||
|
||||
for (const module of modules) {
|
||||
module.used = false;
|
||||
if (!module.used) module.used = false;
|
||||
}
|
||||
|
||||
/** @type {[Module, DependenciesBlock, UsedExports][]} */
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
export default function createB() {
|
||||
return "b";
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export default function createC() {
|
||||
return "c";
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
import { a } from "./module";
|
||||
|
||||
export default a();
|
|
@ -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();
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
exports.noTests = true;
|
|
@ -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"
|
||||
)
|
||||
})
|
||||
]
|
||||
};
|
|
@ -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");
|
||||
});
|
|
@ -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"
|
||||
})
|
||||
]
|
||||
};
|
|
@ -27,6 +27,7 @@ module.exports = {
|
|||
]
|
||||
},
|
||||
optimization: {
|
||||
usedExports: true,
|
||||
sideEffects: true
|
||||
},
|
||||
plugins: [
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
import { constants } from "test-package";
|
||||
|
||||
var x = constants;
|
2
test/configCases/dll-plugin/0-issue-10475/node_modules/test-package/constants.js
generated
vendored
Normal file
2
test/configCases/dll-plugin/0-issue-10475/node_modules/test-package/constants.js
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
export const constant1 = 'constant1';
|
||||
export const constant2 = 'constant2';
|
5
test/configCases/dll-plugin/0-issue-10475/node_modules/test-package/index.js
generated
vendored
Normal file
5
test/configCases/dll-plugin/0-issue-10475/node_modules/test-package/index.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
import * as _constants from './constants';
|
||||
export var constants = _constants;
|
||||
export { default as someFunction } from './someFunction';
|
||||
|
||||
console.log(constants);
|
4
test/configCases/dll-plugin/0-issue-10475/node_modules/test-package/package.json
generated
vendored
Normal file
4
test/configCases/dll-plugin/0-issue-10475/node_modules/test-package/package.json
generated
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"main": "index.js",
|
||||
"sideEffects": false
|
||||
}
|
3
test/configCases/dll-plugin/0-issue-10475/node_modules/test-package/someFunction.js
generated
vendored
Normal file
3
test/configCases/dll-plugin/0-issue-10475/node_modules/test-package/someFunction.js
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
export default function someFunction() {
|
||||
console.log('This is some function');
|
||||
}
|
7
test/configCases/dll-plugin/0-issue-10475/node_modules/test-package/working-constants.js
generated
vendored
Normal file
7
test/configCases/dll-plugin/0-issue-10475/node_modules/test-package/working-constants.js
generated
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
export const constant1 = 'constant1';
|
||||
export const constant2 = 'constant2';
|
||||
|
||||
export default {
|
||||
constant1,
|
||||
constant2,
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
exports.noTests = true;
|
|
@ -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"
|
||||
)
|
||||
})
|
||||
]
|
||||
};
|
|
@ -0,0 +1,3 @@
|
|||
it("should have all modules", () => {
|
||||
require("dll/index.js");
|
||||
});
|
|
@ -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"
|
||||
})
|
||||
]
|
||||
};
|
Loading…
Reference in New Issue