Skip to content

Commit 2acaf76

Browse files
committed
Merge branch 'master' into fix-help-output-test-5345
# Conflicts: # bin/webpack.js
2 parents 20d6f23 + e9a8e35 commit 2acaf76

122 files changed

Lines changed: 1929 additions & 409 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.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/test/fixtures/temp-cache-fixture
55
/benchmark/js
66
/benchmark/fixtures
7-
/examples/*/js
7+
/examples/**/js
88
/coverage
99
.DS_Store
1010
*.log

README.md

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
<div align="center">
2+
<a href="https://github.com/webpack/webpack">
3+
<img width="200" heigth="200" src="https://webpack.js.org/assets/icon-square-big.svg">
4+
</a>
5+
<br>
6+
<br>
7+
18
[![npm][npm]][npm-url]
9+
210
[![node][node]][node-url]
311
[![deps][deps]][deps-url]
412
[![tests][tests]][tests-url]
513
[![builds][builds]][builds-url]
614
[![coverage][cover]][cover-url]
715
[![licenses][licenses]][licenses-url]
816

9-
<div align="center">
10-
<a href="https://github.com/webpack/webpack">
11-
<img width="200" heigth="200" src="https://webpack.js.org/assets/icon-square-big.svg">
12-
</a>
13-
<br>
1417
<br>
1518
<a href="https://npmjs.com/package/webpack">
1619
<img src="https://img.shields.io/npm/dm/webpack.svg">
@@ -32,10 +35,18 @@
3235

3336
<h2 align="center">Install</h2>
3437

38+
Install with npm:
39+
3540
```bash
3641
npm install --save-dev webpack
3742
```
3843

44+
Install with yarn:
45+
46+
```bash
47+
yarn add webpack --dev
48+
```
49+
3950
<h2 align="center">Introduction</h2>
4051

4152
> The README reflects webpack v2.x, webpack v1.x [documentation can be found here](https://webpack.github.io/docs/?utm_source=github&utm_medium=readme&utm_campaign=top).
@@ -120,7 +131,7 @@ or are automatically applied via regex from your webpack configuration.
120131
|Name|Status|Description|
121132
|:--:|:----:|:----------|
122133
|<a href="https://github.com/webpack/json-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/json.svg"></a>|![json-npm]|Loads a JSON file (included by default)|
123-
|<a href="https://github.com/webpack/json5-loader"><img width="48" height="48" src="https://cdn.rawgit.com/json5/json5-logo/master/json5-logo.svg"></a>|![json5-npm]|Loads and transpiles a JSON 5 file|
134+
|<a href="https://github.com/webpack/json5-loader"><img width="48" height="10.656" src="https://cdn.rawgit.com/json5/json5-logo/master/json5-logo.svg"></a>|![json5-npm]|Loads and transpiles a JSON 5 file|
124135
|<a href="https://github.com/awnist/cson-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/coffeescript.svg"></a>|![cson-npm]|Loads and transpiles a CSON file|
125136

126137

@@ -183,17 +194,17 @@ or are automatically applied via regex from your webpack configuration.
183194
[stylus-npm]: https://img.shields.io/npm/v/stylus-loader.svg
184195
[postcss-npm]: https://img.shields.io/npm/v/postcss-loader.svg
185196

186-
#### Linting && Testing
197+
#### Linting & Testing
187198

188199
|Name|Status|Description|
189200
|:--:|:----:|:----------|
190201
|<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)|
191202
|<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|
192-
|<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|
203+
|<a href="https://github.com/webpack-contrib/jshint-loader"><img width="48" height="20.64" src="http://jshint.com/res/jshint-dark.png"></a>|![jshint-npm]|PreLoader for linting code using JSHint|
193204

194205
[mocha-npm]: https://img.shields.io/npm/v/mocha-loader.svg
195206
[eslint-npm]: https://img.shields.io/npm/v/eslint-loader.svg
196-
[jshint-npm]: https://img.shields.io/npm/v/jslint-loader.svg
207+
[jshint-npm]: https://img.shields.io/npm/v/jshint-loader.svg
197208
[jscs-npm]: https://img.shields.io/npm/v/jscs-loader.svg
198209

199210
#### Frameworks
@@ -264,7 +275,7 @@ If you create a loader or plugin, we would <3 for you to open source it, and put
264275

265276
<h2 align="center">Support</h2>
266277

267-
We consider webpack to be a low-level tool used not only individuals but also layered beneath other awesome tools. Because of it's flexibility, webpack isn't always the _easiest_ entry-level solution, however we do believe it is the most powerful. That said, we're always looking for ways improve and simplify the tool without compromising functionality. If you have any ideas on ways to accomplish this, we're all ears!
278+
We consider webpack to be a low-level tool used not only individually but also layered beneath other awesome tools. Because of it's flexibility, webpack isn't always the _easiest_ entry-level solution, however we do believe it is the most powerful. That said, we're always looking for ways improve and simplify the tool without compromising functionality. If you have any ideas on ways to accomplish this, we're all ears!
268279

269280
If you're just getting started, take a look at [our new docs and concepts page](https://webpack.js.org/concepts/). This has a high level overview that is great for beginners!!
270281

@@ -314,7 +325,7 @@ If you have discovered a 🐜 or have a feature suggestion, feel free to create
314325
<img width="150" height="150" src="https://github.com/bebraw.png?s=150">
315326
<br>
316327
<a href="https://github.com/bebraw">Juho Vepsäläinen</a>
317-
<p>Documentation<p>
328+
<p>Documentation</p>
318329
<br>
319330
<p>Author</p>
320331
<a href="https://leanpub.com/survivejs-webpack">
@@ -354,23 +365,33 @@ This is how we use the donations:
354365

355366
<h2 align="center">Premium Partners</h2>
356367

368+
<div align="center">
369+
357370
<a href="https://www.ag-grid.com/?utm_source=webpack&utm_medium=banner&utm_campaign=sponsorship" target="_blank"><img align="center" src="https://raw.githubusercontent.com/webpack/media/2b399d58/horiz-banner-ad-ag-grid.png">
358371
</a>
359372

373+
</div>
374+
360375
<h2 align="center">Other Backers and Sponsors</h2>
361376

362377
Before we started using OpenCollective, donations were made anonymously. Now that we have made the switch, we would like to acknowledge these sponsors (and the ones who continue to donate using OpenCollective). If we've missed someone, please send us a PR, and we'll add you to this list.
363378

379+
<div align="center">
380+
364381
[Google Angular Team](https://angular.io/), [Architects.io](http://architects.io/),
365382
<a href="https://moonmail.io" target="_blank" title="Email Marketing Software"><img
366383
src="https://static.moonmail.io/moonmail-logo.svg" height="30" alt="MoonMail"></a>
367384
<a href="https://monei.net" target="_blank" title="Best payment gateway rates"><img
368385
src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
369386

387+
</div>
388+
370389
<h2 align="center">Sponsors</h2>
371390

372391
[Become a sponsor](https://opencollective.com/webpack#sponsor) and get your logo on our README on Github with a link to your site.
373392

393+
<div align="center">
394+
374395
<a href="https://opencollective.com/webpack/sponsor/0/website?requireActive=false" target="_blank"><img src="https://opencollective.com/webpack/sponsor/0/avatar.svg?requireActive=false"></a>
375396
<a href="https://opencollective.com/webpack/sponsor/1/website?requireActive=false" target="_blank"><img src="https://opencollective.com/webpack/sponsor/1/avatar.svg?requireActive=false"></a>
376397
<a href="https://opencollective.com/webpack/sponsor/2/website?requireActive=false" target="_blank"><img src="https://opencollective.com/webpack/sponsor/2/avatar.svg?requireActive=false"></a>
@@ -402,6 +423,8 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
402423
<a href="https://opencollective.com/webpack/sponsor/28/website?requireActive=false" target="_blank"><img src="https://opencollective.com/webpack/sponsor/28/avatar.svg?requireActive=false"></a>
403424
<a href="https://opencollective.com/webpack/sponsor/29/website?requireActive=false" target="_blank"><img src="https://opencollective.com/webpack/sponsor/29/avatar.svg?requireActive=false"></a>
404425

426+
</div>
427+
405428
<h2 align="center">Backers</h2>
406429

407430
[Become a backer](https://opencollective.com/webpack#backer) and get your image on our README on Github with a link to your site.

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/webpack.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,16 +366,14 @@ yargs.parse(process.argv.slice(2), (err, argv, output) => {
366366
process.stdout.write(statsString + "\n");
367367
}
368368
if(!options.watch && stats.hasErrors()) {
369-
process.on("exit", function() {
370-
process.exit(2); // eslint-disable-line
371-
});
369+
process.exitCode = 2;
372370
}
373371
}
374372
if(firstOptions.watch || options.watch) {
375373
var watchOptions = firstOptions.watchOptions || firstOptions.watch || options.watch || {};
376374
if(watchOptions.stdin) {
377375
process.stdin.on("end", function() {
378-
process.exit(0); // eslint-disable-line
376+
process.exit(); // eslint-disable-line
379377
});
380378
process.stdin.resume();
381379
}

examples/build-common.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
var cp = require("child_process");
6-
var tc = require("./template-common");
7-
var fs = require("fs");
5+
"use strict";
86

9-
var extraArgs = "";
7+
const cp = require("child_process");
8+
const path = require("path");
9+
const tc = require("./template-common");
10+
const fs = require("fs");
1011

11-
var targetArgs = global.NO_TARGET_ARGS ? "" : " ./example.js js/output.js";
12-
var displayReasons = global.NO_REASONS ? "" : " --display-reasons --display-used-exports --display-provided-exports";
13-
cp.exec("node ../../bin/webpack.js" + displayReasons + " --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path \"js/\" -p " + extraArgs + targetArgs, function(error, stdout, stderr) {
12+
const extraArgs = "";
13+
14+
const targetArgs = global.NO_TARGET_ARGS ? "" : " ./example.js js/output.js";
15+
const displayReasons = global.NO_REASONS ? "" : " --display-reasons --display-used-exports --display-provided-exports";
16+
cp.exec(`node ${path.resolve(__dirname, "../bin/webpack.js")} ${displayReasons} --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path "js/" -p ${extraArgs} ${targetArgs}`, function(error, stdout, stderr) {
1417
if(stderr)
1518
console.log(stderr);
1619
if(error !== null)
1720
console.log(error);
21+
let readme;
1822
try {
19-
var readme = tc.replaceResults(fs.readFileSync(require("path").join(process.cwd(), "template.md"), "utf-8"), process.cwd(), stdout.replace(/[\r\n]*$/, ""), "min");
23+
readme = tc.replaceResults(fs.readFileSync(require("path").join(process.cwd(), "template.md"), "utf-8"), process.cwd(), stdout.replace(/[\r\n]*$/, ""), "min");
2024
} catch(e) {
2125
console.log(stderr);
2226
throw e;
2327
}
24-
cp.exec("node ../../bin/webpack.js" + displayReasons + " --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path \"js/\" --output-pathinfo " + extraArgs + targetArgs, function(error, stdout, stderr) {
28+
cp.exec(`node ${path.resolve(__dirname, "../bin/webpack.js")} ${displayReasons} --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path "js/" --output-pathinfo ${extraArgs} ${targetArgs}`, function(error, stdout, stderr) {
2529
console.log(stdout);
2630
if(stderr)
2731
console.log(stderr);

examples/buildAll.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
var cp = require('child_process');
2-
var path = require("path");
3-
var fs = require("fs");
1+
"use strict";
42

5-
var cmds = fs.readdirSync(__dirname).filter(function(dirname) {
6-
return fs.statSync(path.join(__dirname, dirname)).isDirectory() && dirname !== "node_modules";
7-
}).sort().map(function(dirname) {
3+
const cp = require("child_process");
4+
const examples = require("./examples");
5+
6+
const cmds = examples.map(function(dirname) {
87
return "cd " + dirname + " && node build.js";
98
});
109

11-
var stack = function() {
12-
console.log("done");
13-
};
14-
for(var i = cmds.length-1; i >= 0; i--) {
15-
var cmd = cmds[i];
16-
stack = (function(next, cmd) {
17-
return function() {
18-
console.log(cmd);
19-
cp.exec(cmd, function(error, stdout, stderr) {
20-
if(error) console.error(error);
21-
else if(stderr) console.error(stderr), next();
22-
else next();
23-
});
24-
}
25-
}(stack, cmd));
10+
let i = 0;
11+
for(const cmd of cmds.reverse()) {
12+
console.log(`[${++i}/${cmds.length}] ${cmd}`);
13+
cp.execSync(cmd, { encoding: "utf-8" });
2614
}
27-
stack();
15+
console.log("done");

0 commit comments

Comments
 (0)