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 #16935 from snitin315/fix/dll-plugin-contenthash
fix: support `[contenthash]` template in DllPlugin's `name` option
- Loading branch information
Showing
24 changed files
with
161 additions
and
1 deletion.
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
1 change: 1 addition & 0 deletions
1
test/configCases/dll-plugin/0-create-dll-with-contenthash/_d.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 @@ | ||
import "./d"; |
3 changes: 3 additions & 0 deletions
3
test/configCases/dll-plugin/0-create-dll-with-contenthash/_e.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 "./e1"; | ||
import "./e2"; | ||
import "./e"; |
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 @@ | ||
module.exports = "a"; |
3 changes: 3 additions & 0 deletions
3
test/configCases/dll-plugin/0-create-dll-with-contenthash/b.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 @@ | ||
module.exports = function() { | ||
return import("./c"); | ||
} |
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 "c"; |
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 "d"; |
4 changes: 4 additions & 0 deletions
4
test/configCases/dll-plugin/0-create-dll-with-contenthash/e.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,4 @@ | ||
export * from "./e1"; | ||
export * from "./ee2"; | ||
|
||
console.log.bind(console); // side effect to avoid removing module |
3 changes: 3 additions & 0 deletions
3
test/configCases/dll-plugin/0-create-dll-with-contenthash/e1.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 * from "./ee1"; | ||
|
||
console.log.bind(console); // side effect to avoid removing module |
3 changes: 3 additions & 0 deletions
3
test/configCases/dll-plugin/0-create-dll-with-contenthash/e2.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 * from "./ee2"; | ||
|
||
console.log.bind(console); // side effect to avoid removing module |
2 changes: 2 additions & 0 deletions
2
test/configCases/dll-plugin/0-create-dll-with-contenthash/ee1.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,2 @@ | ||
export var x1 = 123; | ||
export var y1 = 456; |
2 changes: 2 additions & 0 deletions
2
test/configCases/dll-plugin/0-create-dll-with-contenthash/ee2.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,2 @@ | ||
export var x2 = 123; | ||
export var y2 = 456; |
1 change: 1 addition & 0 deletions
1
test/configCases/dll-plugin/0-create-dll-with-contenthash/f.jsx
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 @@ | ||
module.exports = 'f'; |
4 changes: 4 additions & 0 deletions
4
test/configCases/dll-plugin/0-create-dll-with-contenthash/g-loader.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,4 @@ | ||
/** @type {import("../../../../").LoaderDefinition} */ | ||
module.exports = function (source) { | ||
return source; | ||
}; |
1 change: 1 addition & 0 deletions
1
test/configCases/dll-plugin/0-create-dll-with-contenthash/g.abc.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 @@ | ||
module.exports = typeof module.id; |
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 { B } from "./h1.js"; |
2 changes: 2 additions & 0 deletions
2
test/configCases/dll-plugin/0-create-dll-with-contenthash/h1.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,2 @@ | ||
export { A } from "./ha.js"; | ||
export { B } from "./hb.js"; |
1 change: 1 addition & 0 deletions
1
test/configCases/dll-plugin/0-create-dll-with-contenthash/ha.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 @@ | ||
export const A = "A"; |
1 change: 1 addition & 0 deletions
1
test/configCases/dll-plugin/0-create-dll-with-contenthash/hb.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 @@ | ||
export const B = "B"; |
1 change: 1 addition & 0 deletions
1
test/configCases/dll-plugin/0-create-dll-with-contenthash/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; |
44 changes: 44 additions & 0 deletions
44
test/configCases/dll-plugin/0-create-dll-with-contenthash/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,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 | ||
}) | ||
] | ||
}; |
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,2 @@ | ||
export * from "dll/e1"; | ||
export * from "dll/e2"; |
60 changes: 60 additions & 0 deletions
60
test/configCases/dll-plugin/4-use-dll-with-contenthash/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,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"); | ||
}); |
17 changes: 17 additions & 0 deletions
17
test/configCases/dll-plugin/4-use-dll-with-contenthash/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,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"] | ||
}) | ||
] | ||
}; |