Skip to content

Commit 31ee49b

Browse files
First stab at SourceMapDevToolPlugin excludeChunks option
1 parent b1da5ed commit 31ee49b

5 files changed

Lines changed: 46 additions & 0 deletions

File tree

lib/SourceMapDevToolPlugin.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function SourceMapDevToolPlugin(options, sourceMappingURLComment, moduleFilename
2222
this.moduleFilenameTemplate = options.moduleFilenameTemplate || "webpack:///[resourcePath]";
2323
this.fallbackModuleFilenameTemplate = options.fallbackModuleFilenameTemplate || "webpack:///[resourcePath]?[hash]";
2424
this.cheapMode = options.cheapMode;
25+
this.excludeChunks = options.excludeChunks;
2526
}
2627
}
2728
module.exports = SourceMapDevToolPlugin;
@@ -32,6 +33,7 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
3233
var fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate;
3334
var requestShortener = new RequestShortener(compiler.context);
3435
var cheapMode = this.cheapMode;
36+
var excludeChunks = this.excludeChunks;
3537
compiler.plugin("compilation", function(compilation) {
3638
if(cheapMode) {
3739
compilation.moduleTemplate.plugin("module", function(source, module) {
@@ -48,6 +50,9 @@ SourceMapDevToolPlugin.prototype.apply = function(compiler) {
4850
var allModuleFilenames = [];
4951
var tasks = [];
5052
chunks.forEach(function(chunk) {
53+
if (excludeChunks && excludeChunks.indexOf(chunk.name) !== -1) {
54+
return;
55+
}
5156
chunk.files.slice().map(function(file) {
5257
var asset = this.assets[file];
5358
if(asset.__SourceMapDevTool_Data) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
it("should include test.js in SourceMap for bundle0 chunk", function() {
2+
var fs = require("fs");
3+
var source = fs.readFileSync(__filename + ".map", "utf-8");
4+
var map = JSON.parse(source);
5+
map.sources.should.containEql("webpack:///./test.js");
6+
});
7+
8+
it("should not produce a SourceMap for vendors chunk", function() {
9+
var fs = require("fs"),
10+
path = require("path"),
11+
assert = require("assert");
12+
fs.existsSync(path.join(__dirname, "vendors.js.map")).should.be.false;
13+
});
14+
15+
require.include("./test.js");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var foo = {};
2+
3+
module.exports = foo;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var bar = {};
2+
3+
module.exports = bar;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var webpack = require("../../../../");
2+
module.exports = {
3+
node: {
4+
__dirname: false,
5+
__filename: false
6+
},
7+
entry: {
8+
bundle0: ["./index.js"],
9+
vendors: ["./vendors.js"]
10+
},
11+
output: {
12+
filename: "[name].js"
13+
},
14+
plugins: [
15+
new webpack.SourceMapDevToolPlugin({
16+
filename: "[file].map",
17+
excludeChunks: ["vendors"]
18+
})
19+
]
20+
};

0 commit comments

Comments
 (0)