Skip to content

Commit dd4e58a

Browse files
authored
Merge pull request webpack#5268 from webpack/backport/performance
Backport performance improvements and devtool fixes to webpack 2
2 parents 7cfd2c4 + a333f36 commit dd4e58a

12 files changed

+68
-34
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ language: node_js
44
branches:
55
only:
66
- master
7+
- webpack-2
78

89
cache:
910
directories:
@@ -13,10 +14,10 @@ cache:
1314
matrix:
1415
include:
1516
- os: linux
16-
node_js: "7"
17+
node_js: "8"
1718
env: NO_WATCH_TESTS=1 JOB_PART=lint
1819
- os: linux
19-
node_js: "7"
20+
node_js: "8"
2021
env: NO_WATCH_TESTS=1 JOB_PART=test
2122
- os: linux
2223
node_js: "6"

appveyor.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
branches:
55
only:
66
- master
7+
- webpack-2
78

89
init:
910
- git config --global core.autocrlf input
@@ -13,17 +14,17 @@ clone_depth: 50
1314
# what combinations to test
1415
environment:
1516
matrix:
16-
- nodejs_version: 7
17+
- nodejs_version: 8
1718
job_part: test
1819
- nodejs_version: 6
1920
job_part: test
2021

2122
install:
2223
- ps: Install-Product node $env:nodejs_version x64
2324
- npm install yarn -g
24-
- yarn install
25-
- yarn link || yarn link
26-
- yarn link webpack
25+
- yarn install --frozen-lockfile
26+
- yarn link --frozen-lockfile || yarn link --frozen-lockfile
27+
- yarn link webpack --frozen-lockfile
2728

2829
build: off
2930

ci/travis-install.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22
set -ev
33

4-
yarn link || true && yarn link webpack;
4+
yarn link --frozen-lockfile || true && yarn link webpack --frozen-lockfile;
5+
6+
yarn --frozen-lockfile
57

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ machine:
88

99
dependencies:
1010
pre:
11-
- case $CIRCLE_NODE_INDEX in 0) NODE_VERSION=4 ;; 1) NODE_VERSION=7 ;; esac; nvm install $NODE_VERSION && nvm alias default $NODE_VERSION
11+
- case $CIRCLE_NODE_INDEX in 0) NODE_VERSION=4 ;; 1) NODE_VERSION=8 ;; esac; nvm install $NODE_VERSION && nvm alias default $NODE_VERSION
1212
override:
1313
- yarn
1414
- yarn link || true && yarn link webpack

input.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/EvalSourceMapDevToolModuleTemplatePlugin.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
1010
class EvalSourceMapDevToolModuleTemplatePlugin {
1111
constructor(compilation, options) {
1212
this.compilation = compilation;
13-
this.sourceMapComment = options.append || "//# sourceMappingURL=[url]";
13+
this.sourceMapComment = options.append || "//# sourceURL=[module]\n//# sourceMappingURL=[url]";
1414
this.moduleFilenameTemplate = options.moduleFilenameTemplate || "webpack:///[resource-path]?[hash]";
1515
this.options = options;
1616
}
@@ -61,13 +61,14 @@ class EvalSourceMapDevToolModuleTemplatePlugin {
6161
sourceMap.sourceRoot = options.sourceRoot || "";
6262
sourceMap.file = `${module.id}.js`;
6363

64-
const footer = self.sourceMapComment.replace(/\[url\]/g, `data:application/json;charset=utf-8;base64,${new Buffer(JSON.stringify(sourceMap), "utf8").toString("base64")}`); //eslint-disable-line
64+
const footer = self.sourceMapComment.replace(/\[url\]/g, `data:application/json;charset=utf-8;base64,${new Buffer(JSON.stringify(sourceMap), "utf8").toString("base64")}`) + //eslint-disable-line
65+
`\n//# sourceURL=webpack-internal:///${module.id}\n`; // workaround for chrome bug
6566
source.__EvalSourceMapDevToolData = new RawSource(`eval(${JSON.stringify(content + footer)});`);
6667
return source.__EvalSourceMapDevToolData;
6768
});
6869
moduleTemplate.plugin("hash", function(hash) {
6970
hash.update("eval-source-map");
70-
hash.update("1");
71+
hash.update("2");
7172
});
7273
}
7374
}

lib/SourceMapDevToolPlugin.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"use strict";
66

77
const path = require("path");
8+
const crypto = require("crypto");
89
const RequestShortener = require("./RequestShortener");
910
const ConcatSource = require("webpack-sources").ConcatSource;
1011
const RawSource = require("webpack-sources").RawSource;
@@ -131,6 +132,7 @@ class SourceMapDevToolPlugin {
131132
if(currentSourceMappingURLComment !== false && /\.css($|\?)/i.test(file)) {
132133
currentSourceMappingURLComment = currentSourceMappingURLComment.replace(/^\n\/\/(.*)$/, "\n/*$1*/");
133134
}
135+
const sourceMapString = JSON.stringify(sourceMap);
134136
if(sourceMapFilename) {
135137
let filename = file;
136138
let query = "";
@@ -139,22 +141,25 @@ class SourceMapDevToolPlugin {
139141
query = filename.substr(idx);
140142
filename = filename.substr(0, idx);
141143
}
142-
const sourceMapFile = compilation.getPath(sourceMapFilename, {
144+
let sourceMapFile = compilation.getPath(sourceMapFilename, {
143145
chunk,
144146
filename,
145147
query,
146148
basename: basename(filename)
147149
});
150+
if(sourceMapFile.indexOf("[contenthash]") !== -1) {
151+
sourceMapFile = sourceMapFile.replace(/\[contenthash\]/g, crypto.createHash("md5").update(sourceMapString).digest("hex"));
152+
}
148153
const sourceMapUrl = path.relative(path.dirname(file), sourceMapFile).replace(/\\/g, "/");
149154
if(currentSourceMappingURLComment !== false) {
150155
asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment.replace(/\[url\]/g, sourceMapUrl));
151156
}
152-
asset.__SourceMapDevToolData[sourceMapFile] = compilation.assets[sourceMapFile] = new RawSource(JSON.stringify(sourceMap));
157+
asset.__SourceMapDevToolData[sourceMapFile] = compilation.assets[sourceMapFile] = new RawSource(sourceMapString);
153158
chunk.files.push(sourceMapFile);
154159
} else {
155160
asset.__SourceMapDevToolData[file] = compilation.assets[file] = new ConcatSource(new RawSource(source), currentSourceMappingURLComment
156-
.replace(/\[map\]/g, () => JSON.stringify(sourceMap))
157-
.replace(/\[url\]/g, () => `data:application/json;charset=utf-8;base64,${new Buffer(JSON.stringify(sourceMap), "utf-8").toString("base64")}`) // eslint-disable-line
161+
.replace(/\[map\]/g, () => sourceMapString)
162+
.replace(/\[url\]/g, () => `data:application/json;charset=utf-8;base64,${new Buffer(sourceMapString, "utf-8").toString("base64")}`) // eslint-disable-line
158163
);
159164
}
160165
});

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"ajv": "^4.7.0",
1010
"ajv-keywords": "^1.1.1",
1111
"async": "^2.1.2",
12-
"enhanced-resolve": "^3.0.0",
12+
"enhanced-resolve": "^3.3.0",
1313
"interpret": "^1.0.0",
1414
"json-loader": "^0.5.4",
1515
"json5": "^0.5.1",
@@ -23,7 +23,7 @@
2323
"tapable": "~0.2.5",
2424
"uglify-js": "^2.8.27",
2525
"watchpack": "^1.3.1",
26-
"webpack-sources": "^0.2.3",
26+
"webpack-sources": "^1.0.1",
2727
"yargs": "^6.0.0"
2828
},
2929
"license": "MIT",
@@ -88,23 +88,23 @@
8888
"schemas/"
8989
],
9090
"scripts": {
91-
"test": "mocha test/*.test.js --harmony --check-leaks",
91+
"test": "mocha test/*.test.js --max_old_space_size=4096 --harmony --check-leaks",
9292
"travis:test": "npm run cover:min",
9393
"travis:lint": "npm run lint-files && npm run nsp",
9494
"travis:benchmark": "npm run benchmark",
95-
"appveyor:test": "node --max_old_space_size=4096 node_modules\\mocha\\bin\\mocha --harmony test/*.test.js",
95+
"appveyor:test": "node node_modules\\mocha\\bin\\mocha --max_old_space_size=4096 --harmony test/*.test.js",
9696
"appveyor:benchmark": "npm run benchmark",
97-
"circleci:test": "node --max_old_space_size=4096 node_modules/mocha/bin/mocha --harmony test/*.test.js",
97+
"circleci:test": "node node_modules/mocha/bin/mocha --max_old_space_size=4096 --harmony test/*.test.js",
9898
"circleci:lint": "npm run lint-files && npm run nsp",
9999
"build:examples": "cd examples && node buildAll.js",
100100
"pretest": "npm run lint-files",
101101
"lint-files": "npm run lint && npm run beautify-lint",
102102
"lint": "eslint lib bin hot buildin \"test/**/webpack.config.js\" \"test/binCases/**/test.js\" \"examples/**/webpack.config.js\"",
103103
"beautify-lint": "beautify-lint \"lib/**/*.js\" \"hot/**/*.js\" \"bin/**/*.js\" \"benchmark/*.js\" \"test/*.js\"",
104104
"nsp": "nsp check --output summary",
105-
"benchmark": "mocha test/*.benchmark.js --harmony -R spec",
106-
"cover": "node --harmony ./node_modules/istanbul/lib/cli.js cover -x '**/*.runtime.js' node_modules/mocha/bin/_mocha -- test/*.test.js",
107-
"cover:min": "node --harmony ./node_modules/.bin/istanbul cover -x '**/*.runtime.js' --report lcovonly node_modules/mocha/bin/_mocha -- test/*.test.js",
105+
"benchmark": "mocha --max_old_space_size=4096 --harmony test/*.benchmark.js -R spec",
106+
"cover": "node --max_old_space_size=4096 --harmony ./node_modules/istanbul/lib/cli.js cover -x '**/*.runtime.js' node_modules/mocha/bin/_mocha -- test/*.test.js",
107+
"cover:min": "node --max_old_space_size=4096 --harmony ./node_modules/.bin/istanbul cover -x '**/*.runtime.js' --report lcovonly node_modules/mocha/bin/_mocha -- test/*.test.js",
108108
"publish-patch": "npm run lint && npm run beautify-lint && mocha && npm version patch && git push && git push --tags && npm publish"
109109
}
110110
}

schemas/webpackOptionsSchema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@
459459
"cachePredicate": {
460460
"instanceof": "Function"
461461
},
462+
"cacheWithContext": {
463+
"type": "boolean"
464+
},
462465
"descriptionFiles": {
463466
"$ref": "#/definitions/common.arrayOfStringValues"
464467
},
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
it("should contain contenthash as query parameter and path", function() {
2+
var fs = require("fs");
3+
var source = fs.readFileSync(__filename, "utf-8");
4+
var match = /sourceMappingURL\s*=.*-([A-Fa-f0-9]{32})\.map\?([A-Fa-f0-9]{32})-([A-Fa-f0-9]{32})/.exec(source);
5+
match.length.should.be.eql(4);
6+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var webpack = require("../../../../");
2+
module.exports = {
3+
node: {
4+
__dirname: false,
5+
__filename: false
6+
},
7+
devtool: "source-map",
8+
output: {
9+
sourceMapFilename: "[file]-[contenthash].map?[contenthash]-[contenthash]",
10+
},
11+
plugins: [
12+
new webpack.optimize.UglifyJsPlugin({
13+
sourceMap: true
14+
})
15+
]
16+
};

yarn.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,9 +1086,9 @@ encoding@^0.1.11:
10861086
dependencies:
10871087
iconv-lite "~0.4.13"
10881088

1089-
enhanced-resolve@^3.0.0:
1090-
version "3.1.0"
1091-
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.1.0.tgz#9f4b626f577245edcf4b2ad83d86e17f4f421dec"
1089+
enhanced-resolve@^3.3.0:
1090+
version "3.3.0"
1091+
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.3.0.tgz#950964ecc7f0332a42321b673b38dc8ff15535b3"
10921092
dependencies:
10931093
graceful-fs "^4.1.2"
10941094
memory-fs "^0.4.0"
@@ -3689,9 +3689,9 @@ source-list-map@^0.1.4, source-list-map@~0.1.7:
36893689
version "0.1.8"
36903690
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-0.1.8.tgz#c550b2ab5427f6b3f21f5afead88c4f5587b2106"
36913691

3692-
source-list-map@^1.1.1:
3693-
version "1.1.2"
3694-
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-1.1.2.tgz#9889019d1024cce55cdc069498337ef6186a11a1"
3692+
source-list-map@^2.0.0:
3693+
version "2.0.0"
3694+
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.0.tgz#aaa47403f7b245a92fbc97ea08f250d6087ed085"
36953695

36963696
source-map@0.4.x, source-map@^0.4.4:
36973697
version "0.4.4"
@@ -4158,11 +4158,11 @@ webpack-sources@^0.1.0:
41584158
source-list-map "~0.1.7"
41594159
source-map "~0.5.3"
41604160

4161-
webpack-sources@^0.2.3:
4162-
version "0.2.3"
4163-
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-0.2.3.tgz#17c62bfaf13c707f9d02c479e0dcdde8380697fb"
4161+
webpack-sources@^1.0.1:
4162+
version "1.0.1"
4163+
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.0.1.tgz#c7356436a4d13123be2e2426a05d1dad9cbe65cf"
41644164
dependencies:
4165-
source-list-map "^1.1.1"
4165+
source-list-map "^2.0.0"
41664166
source-map "~0.5.3"
41674167

41684168
whatwg-fetch@>=0.10.0:

0 commit comments

Comments
 (0)