2018-06-23 21:10:56 +08:00
|
|
|
const DependencyReference = require("../../../../").dependencies
|
|
|
|
.DependencyReference;
|
|
|
|
module.exports = {
|
|
|
|
optimization: {
|
|
|
|
usedExports: true,
|
|
|
|
concatenateModules: true
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
function() {
|
|
|
|
this.hooks.compilation.tap("Test", compilation => {
|
|
|
|
compilation.hooks.dependencyReference.tap(
|
|
|
|
"Test",
|
2019-01-23 19:14:35 +08:00
|
|
|
(ref, dep) => {
|
|
|
|
const module = compilation.moduleGraph.getParentModule(dep);
|
2018-06-23 21:10:56 +08:00
|
|
|
if (
|
|
|
|
module.identifier().endsWith("module.js") &&
|
|
|
|
ref.module &&
|
|
|
|
ref.module.identifier().endsWith("reference.js") &&
|
|
|
|
Array.isArray(ref.importedNames) &&
|
|
|
|
ref.importedNames.includes("unused")
|
|
|
|
) {
|
2019-01-23 19:12:44 +08:00
|
|
|
const newExports = ref.importedNames.filter(item => item !== "unused");
|
2018-06-23 21:10:56 +08:00
|
|
|
return new DependencyReference(
|
2018-07-23 03:01:05 +08:00
|
|
|
() => ref.module,
|
2019-01-23 19:12:44 +08:00
|
|
|
newExports.length > 0 ? newExports : false,
|
2018-06-23 21:10:56 +08:00
|
|
|
ref.weak,
|
|
|
|
ref.order
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|