Skip to content

Commit c726141

Browse files
committed
added test case for commons chunk plugin with umd library
webpack#2066
1 parent f8e3bdf commit c726141

5 files changed

Lines changed: 55 additions & 1 deletion

File tree

‎test/ConfigTestCases.test.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe("ConfigTestCases", function() {
6666
var fn;
6767
var content;
6868
if(Array.isArray(module)) {
69-
var p = "...";
69+
var p = path.join(outputDirectory, module[0]);
7070
content = module.map(function(p) {
7171
var p = path.join(outputDirectory, p);
7272
return fs.readFileSync(p, "utf-8");
@@ -85,6 +85,8 @@ describe("ConfigTestCases", function() {
8585
};
8686
fn.call(module.exports, _require, module, module.exports, outputDirectory, p, _it, globalContext);
8787
return module.exports;
88+
} else if(testConfig.modules && module in testConfig.modules) {
89+
return testConfig.modules[module];
8890
} else return require(module);
8991
}
9092
var filesCount = 0;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var path = require("path");
2+
module.exports = {
3+
vendor: require("fs").readFileSync(path.join(__dirname, "vendor.js"), "utf-8"),
4+
main: require("fs").readFileSync(path.join(__dirname, "main.js"), "utf-8")
5+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require("should");
2+
require.include("external1");
3+
require.ensure([], function() {
4+
require.include("external2");
5+
})
6+
7+
it("should have externals in vendor file", function() {
8+
var a = require("./a");
9+
a.vendor.should.containEql("require(\"external0\")");
10+
a.main.should.containEql("require(\"external1\")");
11+
a.main.should.containEql("require(\"external2\")");
12+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
findBundle: function(i, options) {
3+
return [
4+
"./vendor.js",
5+
"./main.js"
6+
]
7+
},
8+
modules: {
9+
"external0": "module 0",
10+
"external1": "module 1",
11+
"external2": "module 2"
12+
}
13+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var CommonsChunkPlugin = require("../../../../lib/optimize/CommonsChunkPlugin");
2+
module.exports = {
3+
entry: {
4+
vendor: ["external0", "./a"],
5+
main: "./index"
6+
},
7+
target: "web",
8+
output: {
9+
filename: "[name].js",
10+
libraryTarget: "umd"
11+
},
12+
externals: ["external0", "external1", "external2", "fs", "path"],
13+
plugins: [
14+
new CommonsChunkPlugin({
15+
name: "vendor"
16+
})
17+
],
18+
node: {
19+
__filename: false,
20+
__dirname: false
21+
}
22+
}

0 commit comments

Comments
 (0)