mirror of https://github.com/webpack/webpack.git
Merge branch 'master' into next
This commit is contained in:
commit
7f8d5b2aa5
|
@ -225,6 +225,10 @@ class NormalModule extends Module {
|
|||
if(typeof rule === "string") {
|
||||
return content.indexOf(rule) === 0;
|
||||
}
|
||||
|
||||
if(typeof rule === "function") {
|
||||
return rule(content);
|
||||
}
|
||||
// we assume rule is a regexp
|
||||
return rule.test(content);
|
||||
}
|
||||
|
|
|
@ -132,6 +132,7 @@ class SourceMapDevToolPlugin {
|
|||
if(currentSourceMappingURLComment !== false && /\.css($|\?)/i.test(file)) {
|
||||
currentSourceMappingURLComment = currentSourceMappingURLComment.replace(/^\n\/\/(.*)$/, "\n/*$1*/");
|
||||
}
|
||||
const sourceMapString = JSON.stringify(sourceMap);
|
||||
if(sourceMapFilename) {
|
||||
let filename = file;
|
||||
let query = "";
|
||||
|
@ -140,25 +141,25 @@ class SourceMapDevToolPlugin {
|
|||
query = filename.substr(idx);
|
||||
filename = filename.substr(0, idx);
|
||||
}
|
||||
const sourceMapFile = compilation.getPath(sourceMapFilename, {
|
||||
let sourceMapFile = compilation.getPath(sourceMapFilename, {
|
||||
chunk,
|
||||
filename,
|
||||
query,
|
||||
basename: basename(filename)
|
||||
});
|
||||
let sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
|
||||
if(sourceMapUrl.indexOf("[contenthash]") !== -1) {
|
||||
sourceMapUrl = sourceMapUrl.replace(/\[contenthash\]/g, crypto.createHash("md5").update(source).digest("hex"));
|
||||
if(sourceMapFile.indexOf("[contenthash]") !== -1) {
|
||||
sourceMapFile = sourceMapFile.replace(/\[contenthash\]/g, crypto.createHash("md5").update(sourceMapString).digest("hex"));
|
||||
}
|
||||
const sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
|
||||
if(currentSourceMappingURLComment !== false) {
|
||||
asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
|
||||
}
|
||||
asset.__SourceMapDevToolData[sourceMapFile] = compilation.assets[sourceMapFile] = new RawSource(JSON.stringify(sourceMap));
|
||||
asset.__SourceMapDevToolData[sourceMapFile] = compilation.assets[sourceMapFile] = new RawSource(sourceMapString);
|
||||
chunk.files.push(sourceMapFile);
|
||||
} else {
|
||||
asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment
|
||||
.replace(/\[map\]/g, () => JSON.stringify(sourceMap))
|
||||
.replace(/\[url\]/g, () => `data:application/json;charset=utf-8;base64,${new Buffer(JSON.stringify(sourceMap), "utf-8").toString("base64")}`) // eslint-disable-line
|
||||
.replace(/\[map\]/g, () => sourceMapString)
|
||||
.replace(/\[url\]/g, () => `data:application/json;charset=utf-8;base64,${new Buffer(sourceMapString, "utf-8").toString("base64")}`) // eslint-disable-line
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -13,6 +13,8 @@ module.exports = class NodeSourcePlugin {
|
|||
}
|
||||
apply(compiler) {
|
||||
const options = this.options;
|
||||
if(options === false) // allow single kill switch to turn off this plugin
|
||||
return;
|
||||
|
||||
function getPathToModule(module, type) {
|
||||
if(type === true || (type === undefined && nodeLibsBrowser[module])) {
|
||||
|
|
|
@ -159,6 +159,9 @@
|
|||
{
|
||||
"instanceof": "RegExp"
|
||||
},
|
||||
{
|
||||
"instanceof": "Function"
|
||||
},
|
||||
{
|
||||
"items": {
|
||||
"type": "string",
|
||||
|
@ -811,55 +814,64 @@
|
|||
},
|
||||
"node": {
|
||||
"description": "Include polyfills or mocks for various node stuff.",
|
||||
"additionalProperties": {
|
||||
"enum": [
|
||||
false,
|
||||
true,
|
||||
"mock",
|
||||
"empty"
|
||||
]
|
||||
},
|
||||
"properties": {
|
||||
"Buffer": {
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
false,
|
||||
true,
|
||||
"mock"
|
||||
false
|
||||
]
|
||||
},
|
||||
"__dirname": {
|
||||
"enum": [
|
||||
false,
|
||||
true,
|
||||
"mock"
|
||||
]
|
||||
},
|
||||
"__filename": {
|
||||
"enum": [
|
||||
false,
|
||||
true,
|
||||
"mock"
|
||||
]
|
||||
},
|
||||
"console": {
|
||||
"enum": [
|
||||
false,
|
||||
true,
|
||||
"mock"
|
||||
]
|
||||
},
|
||||
"global": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"process": {
|
||||
"enum": [
|
||||
false,
|
||||
true,
|
||||
"mock"
|
||||
]
|
||||
{
|
||||
"additionalProperties": {
|
||||
"enum": [
|
||||
false,
|
||||
true,
|
||||
"mock",
|
||||
"empty"
|
||||
]
|
||||
},
|
||||
"properties": {
|
||||
"Buffer": {
|
||||
"enum": [
|
||||
false,
|
||||
true,
|
||||
"mock"
|
||||
]
|
||||
},
|
||||
"__dirname": {
|
||||
"enum": [
|
||||
false,
|
||||
true,
|
||||
"mock"
|
||||
]
|
||||
},
|
||||
"__filename": {
|
||||
"enum": [
|
||||
false,
|
||||
true,
|
||||
"mock"
|
||||
]
|
||||
},
|
||||
"console": {
|
||||
"enum": [
|
||||
false,
|
||||
true,
|
||||
"mock"
|
||||
]
|
||||
},
|
||||
"global": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"process": {
|
||||
"enum": [
|
||||
false,
|
||||
true,
|
||||
"mock"
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
]
|
||||
},
|
||||
"output": {
|
||||
"$ref": "#/definitions/output"
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
it("should correctly export stuff from not parsed modules", function() {
|
||||
require("./not-parsed-a").should.be.eql("ok");
|
||||
require("./not-parsed-b").should.be.eql("ok");
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
module.exports = "ok";
|
|
@ -0,0 +1,5 @@
|
|||
Object.defineProperty(module, "exports", {
|
||||
get: function() {
|
||||
return "ok";
|
||||
}
|
||||
});
|
|
@ -0,0 +1,7 @@
|
|||
module.exports = {
|
||||
module: {
|
||||
noParse: function(content) {
|
||||
return /not-parsed/.test(content);
|
||||
}
|
||||
}
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
require("should");
|
||||
|
||||
it("should not load node-libs-browser when node option is false", function() {
|
||||
(typeof process).should.be.eql("undefined");
|
||||
});
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = {
|
||||
target: "web",
|
||||
node: false
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
require("should");
|
||||
|
||||
it("should add node-libs-browser to target web by default", function() {
|
||||
process.browser.should.be.eql(true);
|
||||
});
|
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
target: "web",
|
||||
node: {
|
||||
process: true
|
||||
}
|
||||
};
|
|
@ -5,25 +5,19 @@ Child
|
|||
Asset Size Chunks Chunk Names
|
||||
app.js 1.27 kB 0 [emitted] app
|
||||
vendor.bd2b4219dfda1a951495.js 443 bytes 1 [emitted] vendor
|
||||
runtime.js 5.94 kB 2 [emitted] runtime
|
||||
chunk {0} app.js (app) 185 bytes {1} [initial] [rendered]
|
||||
[./entry-1.js] (webpack)/test/statsCases/commons-plugin-issue-4980/entry-1.js 67 bytes {0} [built]
|
||||
[./submodule-a.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-a.js 59 bytes {0} [built]
|
||||
[./submodule-b.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-b.js 59 bytes {0} [built]
|
||||
chunk {1} vendor.bd2b4219dfda1a951495.js (vendor) 87 bytes {2} [initial] [rendered]
|
||||
[./constants.js] (webpack)/test/statsCases/commons-plugin-issue-4980/constants.js 87 bytes {1} [built]
|
||||
chunk {2} runtime.js (runtime) 0 bytes [entry] [rendered]
|
||||
runtime.js 5.78 kB 2 [emitted] runtime
|
||||
[./constants.js] (webpack)/test/statsCases/commons-plugin-issue-4980/constants.js 87 bytes {1} [built]
|
||||
[./entry-1.js] (webpack)/test/statsCases/commons-plugin-issue-4980/entry-1.js 67 bytes {0} [built]
|
||||
[./submodule-a.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-a.js 59 bytes {0} [built]
|
||||
[./submodule-b.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-b.js 59 bytes {0} [built]
|
||||
Child
|
||||
Hash: 2897fe6052020598632c
|
||||
Time: Xms
|
||||
Asset Size Chunks Chunk Names
|
||||
app.js 1.32 kB 0 [emitted] app
|
||||
vendor.bd2b4219dfda1a951495.js 443 bytes 1 [emitted] vendor
|
||||
runtime.js 5.94 kB 2 [emitted] runtime
|
||||
chunk {0} app.js (app) 192 bytes {1} [initial] [rendered]
|
||||
[./entry-2.js] (webpack)/test/statsCases/commons-plugin-issue-4980/entry-2.js 67 bytes {0} [built]
|
||||
[./submodule-a.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-a.js 59 bytes {0} [built]
|
||||
[./submodule-c.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-c.js 66 bytes {0} [built]
|
||||
chunk {1} vendor.bd2b4219dfda1a951495.js (vendor) 87 bytes {2} [initial] [rendered]
|
||||
[./constants.js] (webpack)/test/statsCases/commons-plugin-issue-4980/constants.js 87 bytes {1} [built]
|
||||
chunk {2} runtime.js (runtime) 0 bytes [entry] [rendered]
|
||||
runtime.js 5.78 kB 2 [emitted] runtime
|
||||
[./constants.js] (webpack)/test/statsCases/commons-plugin-issue-4980/constants.js 87 bytes {1} [built]
|
||||
[./entry-2.js] (webpack)/test/statsCases/commons-plugin-issue-4980/entry-2.js 67 bytes {0} [built]
|
||||
[./submodule-a.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-a.js 59 bytes {0} [built]
|
||||
[./submodule-c.js] (webpack)/test/statsCases/commons-plugin-issue-4980/submodule-c.js 66 bytes {0} [built]
|
Loading…
Reference in New Issue