Skip to content

Commit 38264a0

Browse files
committed
allow exact match without extension in dll
1 parent 0445b15 commit 38264a0

8 files changed

Lines changed: 47 additions & 4 deletions

File tree

lib/DelegatedModuleFactoryPlugin.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ DelegatedModuleFactoryPlugin.prototype.apply = function(normalModuleFactory) {
2525
var request = dependency.request;
2626
if(request && request.indexOf(scope + "/") === 0) {
2727
var innerRequest = "." + request.substr(scope.length);
28+
var resolved;
29+
if(innerRequest in this.options.content) {
30+
resolved = this.options.content[innerRequest];
31+
return callback(null, new DelegatedModule(this.options.source, resolved, this.options.type, innerRequest));
32+
}
2833
for(var i = 0; i < this.options.extensions.length; i++) {
2934
var requestPlusExt = innerRequest + this.options.extensions[i];
3035
if(requestPlusExt in this.options.content) {
31-
var resolved = this.options.content[requestPlusExt];
36+
resolved = this.options.content[requestPlusExt];
3237
return callback(null, new DelegatedModule(this.options.source, resolved, this.options.type, requestPlusExt));
3338
}
3439
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function(source) {
2+
return source;
3+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = typeof module.id;

test/configCases/dll-plugin/0-create-dll/webpack.config.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var path = require("path");
22
var webpack = require("../../../../");
33

44
module.exports = {
5-
entry: ["./a", "./b", "./_d", "./_e", "./f"],
5+
entry: ["./a", "./b", "./_d", "./_e", "./f", "./g.abc"],
66
resolve: {
77
extensions: [".js", ".jsx"]
88
},
@@ -11,6 +11,17 @@ module.exports = {
1111
chunkFilename: "[id].dll.js",
1212
libraryTarget: "commonjs2"
1313
},
14+
module: {
15+
rules: [
16+
{
17+
test: /\.abc\.js$/,
18+
loader: "./g-loader.js",
19+
options: {
20+
test: 1
21+
}
22+
}
23+
]
24+
},
1425
plugins: [
1526
new webpack.DllPlugin({
1627
path: path.resolve(__dirname, "../../../js/config/dll-plugin/manifest0.json")

test/configCases/dll-plugin/1-use-dll/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ it("should load an harmony module from dll (star export)", function() {
2828
y1.should.be.eql(456);
2929
y2.should.be.eql(456);
3030
});
31+
32+
it("should load a module with loader applied", function() {
33+
require("dll/g.abc.js").should.be.eql("number");
34+
});

test/configCases/dll-plugin/1-use-dll/webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
scope: "dll",
99
sourceType: "commonjs2",
1010
extensions: [".js", ".jsx"]
11-
})
11+
}),
12+
new webpack.NamedModulesPlugin()
1213
]
1314
};

test/configCases/dll-plugin/2-use-dll-without-scope/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ it("should load an harmony module from dll (star export)", function() {
2424
y1.should.be.eql(456);
2525
y2.should.be.eql(456);
2626
});
27+
28+
it("should load a module with loader applied", function() {
29+
require("../0-create-dll/g.abc.js").should.be.eql("number");
30+
})

test/configCases/dll-plugin/2-use-dll-without-scope/webpack.config.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,26 @@ var path = require("path");
22
var webpack = require("../../../../");
33

44
module.exports = {
5+
module: {
6+
rules: [
7+
{ oneOf: [
8+
{
9+
test: /\.abc\.js$/,
10+
loader: "../0-create-dll/g-loader.js",
11+
options: {
12+
test: 1
13+
}
14+
}
15+
] }
16+
]
17+
},
518
plugins: [
619
new webpack.DllReferencePlugin({
720
manifest: require("../../../js/config/dll-plugin/manifest0.json"),
821
name: "../0-create-dll/dll.js",
922
context: path.resolve(__dirname, "../0-create-dll"),
1023
sourceType: "commonjs2"
11-
})
24+
}),
25+
new webpack.NamedModulesPlugin()
1226
]
1327
};

0 commit comments

Comments
 (0)