Skip to content

Commit

Permalink
Merge pull request #16935 from snitin315/fix/dll-plugin-contenthash
Browse files Browse the repository at this point in the history
fix: support `[contenthash]` template in DllPlugin's `name` option
  • Loading branch information
TheLarkInn committed Apr 12, 2023
2 parents 4cacd7e + fc3bba6 commit ee1a267
Show file tree
Hide file tree
Showing 24 changed files with 161 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/LibManifestPlugin.js
Expand Up @@ -49,7 +49,8 @@ class LibManifestPlugin {
const name =
this.options.name &&
compilation.getPath(this.options.name, {
chunk
chunk,
contentHashType: "javascript"
});
const content = Object.create(null);
for (const module of chunkGraph.getOrderedChunkModulesIterable(
Expand Down
@@ -0,0 +1 @@
import "./d";
@@ -0,0 +1,3 @@
import "./e1";
import "./e2";
import "./e";
@@ -0,0 +1 @@
module.exports = "a";
@@ -0,0 +1,3 @@
module.exports = function() {
return import("./c");
}
@@ -0,0 +1 @@
export default "c";
@@ -0,0 +1 @@
export default "d";
@@ -0,0 +1,4 @@
export * from "./e1";
export * from "./ee2";

console.log.bind(console); // side effect to avoid removing module
@@ -0,0 +1,3 @@
export * from "./ee1";

console.log.bind(console); // side effect to avoid removing module
@@ -0,0 +1,3 @@
export * from "./ee2";

console.log.bind(console); // side effect to avoid removing module
@@ -0,0 +1,2 @@
export var x1 = 123;
export var y1 = 456;
@@ -0,0 +1,2 @@
export var x2 = 123;
export var y2 = 456;
@@ -0,0 +1 @@
module.exports = 'f';
@@ -0,0 +1,4 @@
/** @type {import("../../../../").LoaderDefinition} */
module.exports = function (source) {
return source;
};
@@ -0,0 +1 @@
module.exports = typeof module.id;
@@ -0,0 +1 @@
export { B } from "./h1.js";
@@ -0,0 +1,2 @@
export { A } from "./ha.js";
export { B } from "./hb.js";
@@ -0,0 +1 @@
export const A = "A";
@@ -0,0 +1 @@
export const B = "B";
@@ -0,0 +1 @@
exports.noTests = true;
@@ -0,0 +1,44 @@
var path = require("path");
var webpack = require("../../../../");

/** @type {import("../../../../").Configuration} */
module.exports = {
entry: ["./a", "./b", "./_d", "./_e", "./f", "./g.abc", "./h"],
resolve: {
extensions: [".js", ".jsx"]
},
output: {
filename: "dll.js",
chunkFilename: "[id].dll.js",
libraryTarget: "commonjs2"
},
module: {
rules: [
{
test: /\.abc\.js$/,
loader: "./g-loader.js",
options: {
test: 1
}
},
{
test: /0-create-dll.h/,
sideEffects: false
}
]
},
optimization: {
usedExports: true,
sideEffects: true
},
plugins: [
new webpack.DllPlugin({
path: path.resolve(
__dirname,
"../../../js/config/dll-plugin/manifest0.json"
),
name: "[name]_[contenthash]",
entryOnly: false
})
]
};
2 changes: 2 additions & 0 deletions test/configCases/dll-plugin/4-use-dll-with-contenthash/e.js
@@ -0,0 +1,2 @@
export * from "dll/e1";
export * from "dll/e2";
60 changes: 60 additions & 0 deletions test/configCases/dll-plugin/4-use-dll-with-contenthash/index.js
@@ -0,0 +1,60 @@
import d from "dll/d";
import { x1, y2 } from "./e";
import { x2, y1 } from "dll/e";
import { B } from "dll/h";

it("should load a module from dll", function() {
expect(require("dll/a")).toBe("a");
});

it("should load a module of non-default type without extension from dll", function() {
expect(require("dll/f")).toBe("f");
});

it("should load an async module from dll", function(done) {
require("dll/b")()
.then(function(c) {
expect(c).toEqual(nsObj({ default: "c" }));
done();
})
.catch(done);
});

it("should load an harmony module from dll (default export)", function() {
expect(d).toBe("d");
});

it("should load an harmony module from dll (star export)", function() {
expect(x1).toBe(123);
expect(x2).toBe(123);
expect(y1).toBe(456);
expect(y2).toBe(456);
});

it("should load a module with loader applied", function() {
expect(require("dll/g.abc.js")).toBe("number");
});

it("should give modules the correct ids", function() {
expect(
Object.keys(__webpack_modules__)
.filter(m => !m.startsWith("../.."))
.sort()
).toEqual([
"./index.js",
"dll-reference ../0-create-dll-with-contenthash/dll.js",
"dll/a.js",
"dll/b.js",
"dll/d.js",
"dll/e.js",
"dll/e1.js",
"dll/e2.js",
"dll/f.jsx",
"dll/g.abc.js",
"dll/h.js"
]);
});

it("should not crash on side-effect-free modules", function() {
expect(B).toBe("B");
});
@@ -0,0 +1,17 @@
var webpack = require("../../../../");

/** @type {import("../../../../").Configuration} */
module.exports = {
optimization: {
moduleIds: "named"
},
plugins: [
new webpack.DllReferencePlugin({
manifest: require("../../../js/config/dll-plugin/manifest0.json"), // eslint-disable-line node/no-missing-require
name: "../0-create-dll-with-contenthash/dll.js",
scope: "dll",
sourceType: "commonjs2",
extensions: [".js", ".jsx"]
})
]
};

0 comments on commit ee1a267

Please sign in to comment.