Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport performance improvements and devtool fixes to webpack 2 #5268

Merged
merged 12 commits into from Jul 12, 2017
5 changes: 3 additions & 2 deletions .travis.yml
Expand Up @@ -4,6 +4,7 @@ language: node_js
branches:
only:
- master
- webpack-2

cache:
directories:
Expand All @@ -13,10 +14,10 @@ cache:
matrix:
include:
- os: linux
node_js: "7"
node_js: "8"
env: NO_WATCH_TESTS=1 JOB_PART=lint
- os: linux
node_js: "7"
node_js: "8"
env: NO_WATCH_TESTS=1 JOB_PART=test
- os: linux
node_js: "6"
Expand Down
9 changes: 5 additions & 4 deletions appveyor.yml
Expand Up @@ -4,6 +4,7 @@
branches:
only:
- master
- webpack-2

init:
- git config --global core.autocrlf input
Expand All @@ -13,17 +14,17 @@ clone_depth: 50
# what combinations to test
environment:
matrix:
- nodejs_version: 7
- nodejs_version: 8
job_part: test
- nodejs_version: 6
job_part: test

install:
- ps: Install-Product node $env:nodejs_version x64
- npm install yarn -g
- yarn install
- yarn link || yarn link
- yarn link webpack
- yarn install --frozen-lockfile
- yarn link --frozen-lockfile || yarn link --frozen-lockfile
- yarn link webpack --frozen-lockfile

build: off

Expand Down
4 changes: 3 additions & 1 deletion ci/travis-install.sh
@@ -1,5 +1,7 @@
#!/bin/bash
set -ev

yarn link || true && yarn link webpack;
yarn link --frozen-lockfile || true && yarn link webpack --frozen-lockfile;

yarn --frozen-lockfile

2 changes: 1 addition & 1 deletion circle.yml
Expand Up @@ -8,7 +8,7 @@ machine:

dependencies:
pre:
- case $CIRCLE_NODE_INDEX in 0) NODE_VERSION=4 ;; 1) NODE_VERSION=7 ;; esac; nvm install $NODE_VERSION && nvm alias default $NODE_VERSION
- case $CIRCLE_NODE_INDEX in 0) NODE_VERSION=4 ;; 1) NODE_VERSION=8 ;; esac; nvm install $NODE_VERSION && nvm alias default $NODE_VERSION
override:
- yarn
- yarn link || true && yarn link webpack
Expand Down
1 change: 0 additions & 1 deletion input.js

This file was deleted.

7 changes: 4 additions & 3 deletions lib/EvalSourceMapDevToolModuleTemplatePlugin.js
Expand Up @@ -10,7 +10,7 @@ const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
class EvalSourceMapDevToolModuleTemplatePlugin {
constructor(compilation, options) {
this.compilation = compilation;
this.sourceMapComment = options.append || "//# sourceMappingURL=[url]";
this.sourceMapComment = options.append || "//# sourceURL=[module]\n//# sourceMappingURL=[url]";
this.moduleFilenameTemplate = options.moduleFilenameTemplate || "webpack:///[resource-path]?[hash]";
this.options = options;
}
Expand Down Expand Up @@ -61,13 +61,14 @@ class EvalSourceMapDevToolModuleTemplatePlugin {
sourceMap.sourceRoot = options.sourceRoot || "";
sourceMap.file = `${module.id}.js`;

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
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
`\n//# sourceURL=webpack-internal:///${module.id}\n`; // workaround for chrome bug
source.__EvalSourceMapDevToolData = new RawSource(`eval(${JSON.stringify(content + footer)});`);
return source.__EvalSourceMapDevToolData;
});
moduleTemplate.plugin("hash", function(hash) {
hash.update("eval-source-map");
hash.update("1");
hash.update("2");
});
}
}
Expand Down
13 changes: 9 additions & 4 deletions lib/SourceMapDevToolPlugin.js
Expand Up @@ -5,6 +5,7 @@
"use strict";

const path = require("path");
const crypto = require("crypto");
const RequestShortener = require("./RequestShortener");
const ConcatSource = require("webpack-sources").ConcatSource;
const RawSource = require("webpack-sources").RawSource;
Expand Down Expand Up @@ -131,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 = "";
Expand All @@ -139,22 +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)
});
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
);
}
});
Expand Down
16 changes: 8 additions & 8 deletions package.json
Expand Up @@ -9,7 +9,7 @@
"ajv": "^4.7.0",
"ajv-keywords": "^1.1.1",
"async": "^2.1.2",
"enhanced-resolve": "^3.0.0",
"enhanced-resolve": "^3.3.0",
"interpret": "^1.0.0",
"json-loader": "^0.5.4",
"json5": "^0.5.1",
Expand All @@ -23,7 +23,7 @@
"tapable": "~0.2.5",
"uglify-js": "^2.8.27",
"watchpack": "^1.3.1",
"webpack-sources": "^0.2.3",
"webpack-sources": "^1.0.1",
"yargs": "^6.0.0"
},
"license": "MIT",
Expand Down Expand Up @@ -88,23 +88,23 @@
"schemas/"
],
"scripts": {
"test": "mocha test/*.test.js --harmony --check-leaks",
"test": "mocha test/*.test.js --max_old_space_size=4096 --harmony --check-leaks",
"travis:test": "npm run cover:min",
"travis:lint": "npm run lint-files && npm run nsp",
"travis:benchmark": "npm run benchmark",
"appveyor:test": "node --max_old_space_size=4096 node_modules\\mocha\\bin\\mocha --harmony test/*.test.js",
"appveyor:test": "node node_modules\\mocha\\bin\\mocha --max_old_space_size=4096 --harmony test/*.test.js",
"appveyor:benchmark": "npm run benchmark",
"circleci:test": "node --max_old_space_size=4096 node_modules/mocha/bin/mocha --harmony test/*.test.js",
"circleci:test": "node node_modules/mocha/bin/mocha --max_old_space_size=4096 --harmony test/*.test.js",
"circleci:lint": "npm run lint-files && npm run nsp",
"build:examples": "cd examples && node buildAll.js",
"pretest": "npm run lint-files",
"lint-files": "npm run lint && npm run beautify-lint",
"lint": "eslint lib bin hot buildin \"test/**/webpack.config.js\" \"test/binCases/**/test.js\" \"examples/**/webpack.config.js\"",
"beautify-lint": "beautify-lint \"lib/**/*.js\" \"hot/**/*.js\" \"bin/**/*.js\" \"benchmark/*.js\" \"test/*.js\"",
"nsp": "nsp check --output summary",
"benchmark": "mocha test/*.benchmark.js --harmony -R spec",
"cover": "node --harmony ./node_modules/istanbul/lib/cli.js cover -x '**/*.runtime.js' node_modules/mocha/bin/_mocha -- test/*.test.js",
"cover:min": "node --harmony ./node_modules/.bin/istanbul cover -x '**/*.runtime.js' --report lcovonly node_modules/mocha/bin/_mocha -- test/*.test.js",
"benchmark": "mocha --max_old_space_size=4096 --harmony test/*.benchmark.js -R spec",
"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",
"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",
"publish-patch": "npm run lint && npm run beautify-lint && mocha && npm version patch && git push && git push --tags && npm publish"
}
}
3 changes: 3 additions & 0 deletions schemas/webpackOptionsSchema.json
Expand Up @@ -459,6 +459,9 @@
"cachePredicate": {
"instanceof": "Function"
},
"cacheWithContext": {
"type": "boolean"
},
"descriptionFiles": {
"$ref": "#/definitions/common.arrayOfStringValues"
},
Expand Down
@@ -0,0 +1,6 @@
it("should contain contenthash as query parameter and path", function() {
var fs = require("fs");
var source = fs.readFileSync(__filename, "utf-8");
var match = /sourceMappingURL\s*=.*-([A-Fa-f0-9]{32})\.map\?([A-Fa-f0-9]{32})-([A-Fa-f0-9]{32})/.exec(source);
match.length.should.be.eql(4);
});
@@ -0,0 +1,16 @@
var webpack = require("../../../../");
module.exports = {
node: {
__dirname: false,
__filename: false
},
devtool: "source-map",
output: {
sourceMapFilename: "[file]-[contenthash].map?[contenthash]-[contenthash]",
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
sourceMap: true
})
]
};
20 changes: 10 additions & 10 deletions yarn.lock
Expand Up @@ -1086,9 +1086,9 @@ encoding@^0.1.11:
dependencies:
iconv-lite "~0.4.13"

enhanced-resolve@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.1.0.tgz#9f4b626f577245edcf4b2ad83d86e17f4f421dec"
enhanced-resolve@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.3.0.tgz#950964ecc7f0332a42321b673b38dc8ff15535b3"
dependencies:
graceful-fs "^4.1.2"
memory-fs "^0.4.0"
Expand Down Expand Up @@ -3689,9 +3689,9 @@ source-list-map@^0.1.4, source-list-map@~0.1.7:
version "0.1.8"
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-0.1.8.tgz#c550b2ab5427f6b3f21f5afead88c4f5587b2106"

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

source-map@0.4.x, source-map@^0.4.4:
version "0.4.4"
Expand Down Expand Up @@ -4158,11 +4158,11 @@ webpack-sources@^0.1.0:
source-list-map "~0.1.7"
source-map "~0.5.3"

webpack-sources@^0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-0.2.3.tgz#17c62bfaf13c707f9d02c479e0dcdde8380697fb"
webpack-sources@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.0.1.tgz#c7356436a4d13123be2e2426a05d1dad9cbe65cf"
dependencies:
source-list-map "^1.1.1"
source-list-map "^2.0.0"
source-map "~0.5.3"

whatwg-fetch@>=0.10.0:
Expand Down