Skip to content

Commit 32264b8

Browse files
authored
Merge branch 'master' into feature/improve-module-concat-bailout-messages
2 parents 05b913a + 4b12c56 commit 32264b8

131 files changed

Lines changed: 2868 additions & 2331 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.eslintrc.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module.exports = {
3636
"space-before-function-paren": ["error", "never"],
3737
"space-before-blocks": "error",
3838
"object-curly-spacing": ["error", "always"],
39+
"indent": "off",
3940
"keyword-spacing": ["error", {
4041
"after": false,
4142
"overrides": {

‎README.md‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ within webpack itself use this plugin interface. This makes webpack very
6969
|:--:|:----:|:----------|
7070
|[common-chunks-webpack-plugin][common]|![common-npm]|Generates chunks of common modules shared between entry points and splits them into separate bundles (e.g vendor.bundle.js && app.bundle.js)|
7171
|[extract-text-webpack-plugin][extract]|![extract-npm]|Extracts Text (CSS) from your bundles into a separate file (app.bundle.css)|
72-
|[component-webpack-plugin][component]|![component-npm]|Use components with webpack|
7372
|[compression-webpack-plugin][compression]|![compression-npm]|Prepare compressed versions of assets to serve them with Content-Encoding|
7473
|[i18n-webpack-plugin][i18n]|![i18n-npm]|Adds i18n support to your bundles|
7574
|[html-webpack-plugin][html-plugin]|![html-plugin-npm]| Simplifies creation of HTML files (`index.html`) to serve your bundles|
@@ -191,8 +190,6 @@ or are automatically applied via regex from your webpack configuration.
191190
|<a href="https://github.com/webpack/mocha-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/mocha.svg"></a>|![mocha-npm]|Tests with mocha (Browser/NodeJS)|
192191
|<a href="https://github.com/MoOx/eslint-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/eslint.svg"></a>|![eslint-npm]|PreLoader for linting code using ESLint|
193192
|<a href="https://github.com/webpack/jslint-loader"><img width="48" height="48" src="http://jshint.com/res/jshint-dark.png"></a>|![jshint-npm]|PreLoader for linting code using JSHint|
194-
|<a href="https://github.com/unindented/jscs-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/jscs.svg"></a>|![jscs-npm]|PreLoader for code style checking using JSCS|
195-
196193

197194
[mocha-npm]: https://img.shields.io/npm/v/mocha-loader.svg
198195
[eslint-npm]: https://img.shields.io/npm/v/eslint-loader.svg
@@ -262,6 +259,7 @@ We have also started a series on our [Medium Publication](https://medium.com/web
262259
_Looking to speak about webpack?_ We'd **love** to review your talk abstract/CFP! You can email it to webpack [at] opencollective [dot] com and we can give pointers or tips!!!
263260

264261
<h3 align="center">Creating your own plugins and loaders</h3>
262+
265263
If you create a loader or plugin, we would <3 for you to open source it, and put it on npm. We follow the `x-loader`, `x-webpack-plugin` naming convention.
266264

267265
<h2 align="center">Support</h2>

‎benchmark/createBenchmark.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const webpack = require("webpack");
2+
const path = require("path");
3+
4+
webpack({
5+
context: __dirname,
6+
entry: "./createBenchmark/entry.js",
7+
output: {
8+
path: __dirname,
9+
filename: "benchmark-bundle.js"
10+
},
11+
target: "node",
12+
node: {
13+
__dirname: false
14+
},
15+
plugins: [
16+
new webpack.NamedModulesPlugin(),
17+
new webpack.IgnorePlugin(/^(fsevents|uglify-js)$/),
18+
new webpack.NormalModuleReplacementPlugin(/^.\/loadLoader$/, path.resolve(__dirname, "./createBenchmark/loadLoader"))
19+
]
20+
}, function(err, stats) {
21+
console.log(stats.toString());
22+
});

‎benchmark/createBenchmark/entry.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const webpack = require("webpack");
2+
const MemoryFs = require("memory-fs");
3+
const path = require("path");
4+
5+
const testCase = process.argv[2];
6+
7+
const config = {
8+
context: __dirname,
9+
entry: `./${testCase}`,
10+
output: {
11+
path: path.resolve(__dirname, "output-" + testCase)
12+
},
13+
devtool: process.argv[3]
14+
};
15+
16+
const compiler = webpack(config);
17+
compiler.run((err, stats) => {
18+
if(err) {
19+
console.error(err);
20+
} else {
21+
console.log(stats.toString({
22+
errorDetails: true
23+
}));
24+
}
25+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = (loader, callback) => {
2+
callback(new Error("Loaders are not supported"));
3+
}

‎benchmark/createTestCases.js‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
let avgJs = `
2+
const str = "we" + "do" + "some" + "ops";
3+
for(const x of str.split("")) {
4+
if(x.charCodeAt(0) > 40) {
5+
console.log("omg");
6+
} else {
7+
console.log(Math.random() * 2 + 3 * 2);
8+
}
9+
}
10+
11+
// Some comment
12+
switch(a.b.c.d.f.e.g.h.i) {
13+
case true:
14+
break;
15+
case "magic":
16+
throw new Error("Error!");
17+
case 9:
18+
(function() {
19+
// extra scope
20+
var x = 123;
21+
var y = 456;
22+
var z = x + z * x / y;
23+
x && y && (z = x ? y : x);
24+
}())
25+
}
26+
27+
function a() {}
28+
function b() {}
29+
function c() {}
30+
function d() {}
31+
function e() {}
32+
function f() {}
33+
`
34+
35+
for(var i = 0; i < 2; i++) {
36+
avgJs += `(function() {${avgJs}}());`;
37+
}
38+
39+
const fs = require("fs");
40+
const root = __dirname;
41+
42+
createTree(fs, 100, `${root}/modules-100`);
43+
createTree(fs, 500, `${root}/modules-500`);
44+
createTree(fs, 1000, `${root}/modules-1000`);
45+
createTree(fs, 3000, `${root}/modules-3000`);
46+
createTree(fs, 5000, `${root}/modules-5000`);
47+
48+
function createTree(fs, count, folder) {
49+
fs.mkdirSync(folder);
50+
let remaining = count - 1;
51+
52+
function make(prefix, count, depth) {
53+
if(count === 0) {
54+
fs.writeFileSync(`${folder}/${prefix}.js`, `export default 1;\n${avgJs}`);
55+
} else {
56+
const list = [];
57+
for(let i = 0; i < count; i++) {
58+
if(remaining-- <= 0) break;
59+
if(depth <= 4 && i >= 3 && i <= 4) {
60+
list.push(`const module${i} = import("./${prefix}-${i}");\ncounter += module${i};`);
61+
} else {
62+
list.push(`import module${i} from "./${prefix}-${i}";\ncounter += module${i};`);
63+
}
64+
make(`${prefix}-${i}`, depth > 4 || count > 30 ? 0 : count + depth + i ** 2, depth + 1);
65+
}
66+
fs.writeFileSync(`${folder}/${prefix}.js`, `let counter = 0;\n${list.join("\n")};\nexport default counter;\n${avgJs}`)
67+
}
68+
}
69+
make("index", 2, 0);
70+
}

‎bin/config-optimist.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = function(optimist) {
22
optimist
33
.boolean("help").alias("help", "h").alias("help", "?").describe("help")
44
.string("config").describe("config", "Path to the config file")
5+
.string("config-name").describe("config-name", "Name of the config to use")
56
.string("env").describe("env", "Environment passed to the config, when it is a function")
67
.string("context").describe("context", "The root directory for resolving entry point and stats")
78
.string("entry").describe("entry", "The entry point")

‎bin/config-yargs.js‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var OPTIMIZE_GROUP = "Optimizing options:";
99
module.exports = function(yargs) {
1010
yargs
1111
.help("help")
12-
.alias("help", "h", "?")
12+
.alias("help", "h")
1313
.version()
1414
.alias("version", "v")
1515
.options({
@@ -20,6 +20,12 @@ module.exports = function(yargs) {
2020
defaultDescription: "webpack.config.js or webpackfile.js",
2121
requiresArg: true
2222
},
23+
"config-name": {
24+
type: "string",
25+
describe: "Name of the config to use",
26+
group: CONFIG_GROUP,
27+
requiresArg: true
28+
},
2329
"env": {
2430
describe: "Environment passed to the config, when it is a function",
2531
group: CONFIG_GROUP
@@ -245,12 +251,14 @@ module.exports = function(yargs) {
245251
"bail": {
246252
type: "boolean",
247253
describe: "Abort the compilation on first error",
248-
group: ADVANCED_GROUP
254+
group: ADVANCED_GROUP,
255+
default: null
249256
},
250257
"profile": {
251258
type: "boolean",
252259
describe: "Profile the compilation and include information in stats",
253-
group: ADVANCED_GROUP
260+
group: ADVANCED_GROUP,
261+
default: null
254262
},
255263
"d": {
256264
type: "boolean",

‎bin/convert-argv.js‎

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var path = require("path");
22
var fs = require("fs");
33
fs.existsSync = fs.existsSync || path.existsSync;
44
var interpret = require("interpret");
5+
var prepareOptions = require("../lib/prepareOptions");
56

67
module.exports = function(yargs, argv, convertOptions) {
78

@@ -94,13 +95,7 @@ module.exports = function(yargs, argv, convertOptions) {
9495

9596
var requireConfig = function requireConfig(configPath) {
9697
var options = require(configPath);
97-
var isES6DefaultExportedFunc = (
98-
typeof options === "object" && options !== null && typeof options.default === "function"
99-
);
100-
if(typeof options === "function" || isES6DefaultExportedFunc) {
101-
options = isES6DefaultExportedFunc ? options.default : options;
102-
options = options(argv.env, argv);
103-
}
98+
options = prepareOptions(options, argv);
10499
return options;
105100
};
106101

@@ -135,6 +130,20 @@ module.exports = function(yargs, argv, convertOptions) {
135130
return processConfiguredOptions(options.default);
136131
}
137132

133+
// filter multi-config by name
134+
if(Array.isArray(options) && argv["config-name"]) {
135+
var namedOptions = options.filter(function(opt) {
136+
return opt.name === argv["config-name"];
137+
});
138+
if(namedOptions.length === 0) {
139+
console.error("Configuration with name '" + argv["config-name"] + "' was not found.");
140+
process.exit(-1); // eslint-disable-line
141+
} else if(namedOptions.length === 1) {
142+
return processConfiguredOptions(namedOptions[0]);
143+
}
144+
options = namedOptions;
145+
}
146+
138147
if(Array.isArray(options)) {
139148
options.forEach(processOptions);
140149
} else {
@@ -284,24 +293,30 @@ module.exports = function(yargs, argv, convertOptions) {
284293
ensureObject(options, "entry");
285294
});
286295

287-
function bindLoaders(arg, collection) {
296+
function bindRules(arg) {
288297
ifArgPair(arg, function(name, binding) {
289298
if(name === null) {
290299
name = binding;
291300
binding += "-loader";
292301
}
293-
options.module[collection].push({
294-
test: new RegExp("\\." + name.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + "$"),
302+
var rule = {
303+
test: new RegExp("\\." + name.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + "$"), // eslint-disable-line no-useless-escape
295304
loader: binding
296-
});
305+
};
306+
if(arg === "module-bind-pre") {
307+
rule.enforce = "pre";
308+
} else if(arg === "module-bind-post") {
309+
rule.enforce = "post";
310+
}
311+
options.module.rules.push(rule);
297312
}, function() {
298313
ensureObject(options, "module");
299-
ensureArray(options.module, collection);
314+
ensureArray(options.module, "rules");
300315
});
301316
}
302-
bindLoaders("module-bind", "loaders");
303-
bindLoaders("module-bind-pre", "preLoaders");
304-
bindLoaders("module-bind-post", "postLoaders");
317+
bindRules("module-bind");
318+
bindRules("module-bind-pre");
319+
bindRules("module-bind-post");
305320

306321
var defineObject;
307322
ifArgPair("define", function(name, value) {

‎hot/log-apply-result.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ module.exports = function(updatedModules, renewedModules) {
2020
} else {
2121
log("info", "[HMR] Updated modules:");
2222
renewedModules.forEach(function(moduleId) {
23-
log("info", "[HMR] - " + moduleId);
23+
if(typeof moduleId === "string" && moduleId.indexOf("!") !== -1) {
24+
var parts = moduleId.split("!");
25+
log.groupCollapsed("info", "[HMR] - " + parts.pop());
26+
log("info", "[HMR] - " + moduleId);
27+
log.groupEnd("info");
28+
} else {
29+
log("info", "[HMR] - " + moduleId);
30+
}
2431
});
2532
var numberIds = renewedModules.every(function(moduleId) {
2633
return typeof moduleId === "number";

0 commit comments

Comments
 (0)