webpack 3.10.0 → 3.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -83,7 +83,7 @@ within webpack itself use this plugin interface. This makes webpack very
83
83
  |:--:|:----:|:----------|
84
84
  |[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)|
85
85
  |[extract-text-webpack-plugin][extract]|![extract-npm]|Extracts Text (CSS) from your bundles into a separate file (app.bundle.css)|
86
- |[compression-webpack-plugin][compression]|![compression-npm]|Prepare compressed versions of assets to serve them with Content-Encoding|
86
+ |[compression-webpack-plugin][compression]|![compression-npm]|Prepares compressed versions of assets to serve them with Content-Encoding|
87
87
  |[i18n-webpack-plugin][i18n]|![i18n-npm]|Adds i18n support to your bundles|
88
88
  |[html-webpack-plugin][html-plugin]|![html-plugin-npm]| Simplifies creation of HTML files (`index.html`) to serve your bundles|
89
89
 
@@ -115,7 +115,7 @@ or are automatically applied via regex from your webpack configuration.
115
115
  |Name|Status|Description|
116
116
  |:--:|:----:|:----------|
117
117
  |[raw-loader][raw]|![raw-npm]|Loads raw content of a file (utf-8)|
118
- |[val-loader][val]|![val-npm]|Executes code as module and consider exports as JS code|
118
+ |[val-loader][val]|![val-npm]|Executes code as module and considers exports as JS code|
119
119
  |[url-loader][url]|![url-npm]|Works like the file loader, but can return a Data Url if the file is smaller than a limit|
120
120
  |[file-loader][file]|![file-npm]|Emits the file into the output folder and returns the (relative) url|
121
121
 
@@ -146,10 +146,11 @@ or are automatically applied via regex from your webpack configuration.
146
146
 
147
147
  |Name|Status|Description|
148
148
  |:--:|:----:|:----------|
149
- |<a href="https://github.com/webpack/script-loader">`<script>`</a>|![script-npm]|Executes a JavaScript file once in global context (like in script tag), requires are not parsed|
149
+ |<a href="https://github.com/webpack/script-loader">`<script>`</a>|![script-npm]|Executes a JavaScript file once in global context (like in script tag), `require()`s are not parsed|
150
150
  |<a href="https://github.com/babel/babel-loader"><img width="48" height="48" title="babel-loader" src="https://worldvectorlogo.com/logos/babel-10.svg"></a>|![babel-npm]|Loads ES2015+ code and transpiles to ES5 using <a href="https://github.com/babel/babel">Babel</a>|
151
151
  |<a href="https://github.com/jupl/traceur-loader"><img width="48" height="48" src="https://google.github.com/traceur-compiler/logo/tc.svg"></a>|![traceur-npm]|Loads ES2015+ code and transpiles to ES5 using [Traceur](https://github.com/google/traceur-compiler)|
152
152
  |<a href="https://github.com/TypeStrong/ts-loader"><img width="48" height="48" src="https://cdn.rawgit.com/Microsoft/TypeScript/master/doc/logo.svg"></a>|![type-npm]|Loads TypeScript like JavaScript|
153
+ |[`awesome-typescript-loader`](https://github.com/s-panferov/awesome-typescript-loader)|![awesome-typescript-npm]|Awesome TypeScript loader for webpack|
153
154
  |<a href="https://github.com/webpack/coffee-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/coffeescript.svg"></a>|![coffee-npm]|Loads CoffeeScript like JavaScript|
154
155
 
155
156
 
@@ -158,12 +159,13 @@ or are automatically applied via regex from your webpack configuration.
158
159
  [traceur-npm]: https://img.shields.io/npm/v/traceur-loader.svg
159
160
  [coffee-npm]: https://img.shields.io/npm/v/coffee-loader.svg
160
161
  [type-npm]: https://img.shields.io/npm/v/ts-loader.svg
162
+ [awesome-typescript-npm]: https://img.shields.io/npm/v/awesome-typescript-loader.svg
161
163
 
162
164
  #### Templating
163
165
 
164
166
  |Name|Status|Description|
165
167
  |:--:|:----:|:----------|
166
- |<a href="https://github.com/webpack/html-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/html5.svg"></a>|![html-npm]|Exports HTML as string, require references to static resources|
168
+ |<a href="https://github.com/webpack/html-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/html5.svg"></a>|![html-npm]|Exports HTML as string, requires references to static resources|
167
169
  |<a href="https://github.com/pugjs/pug-loader"><img width="48" height="48" src="https://cdn.rawgit.com/pugjs/pug-logo/master/SVG/pug-final-logo-_-colour-128.svg"></a>|![pug-npm]|Loads Pug templates and returns a function|
168
170
  |<a href="https://github.com/webpack/jade-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/jade-3.svg"></a>|![jade-npm]|Loads Jade templates and returns a function|
169
171
  |<a href="https://github.com/peerigon/markdown-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/markdown.svg"></a>|![md-npm]|Compiles Markdown to HTML|
@@ -215,14 +217,14 @@ or are automatically applied via regex from your webpack configuration.
215
217
  |Name|Status|Description|
216
218
  |:--:|:----:|:----------|
217
219
  |<a href="https://github.com/vuejs/vue-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/vue-9.svg"></a>|![vue-npm]|Loads and compiles Vue Components|
218
- |<a href="https://github.com/JonDum/polymer-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/polymer.svg"></a>|![polymer-npm]|Process HTML & CSS with preprocessor of choice and `require()` Web Components like first-class modules|
220
+ |<a href="https://github.com/webpack-contrib/polymer-webpack-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/polymer.svg"></a>|![polymer-npm]|Process HTML & CSS with preprocessor of choice and `require()` Web Components like first-class modules|
219
221
  |<a href="https://github.com/TheLarkInn/angular2-template-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/angular-icon-1.svg"></a>|![angular-npm]| Loads and compiles Angular 2 Components|
220
222
  |<a href="https://github.com/riot/tag-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/riot.svg"></a>|![riot-npm]| Riot official webpack loader|
221
223
 
222
224
 
223
225
 
224
226
  [vue-npm]: https://img.shields.io/npm/v/vue-loader.svg
225
- [polymer-npm]: https://img.shields.io/npm/v/polymer-loader.svg
227
+ [polymer-npm]: https://img.shields.io/npm/v/polymer-webpack-loader.svg
226
228
  [angular-npm]: https://img.shields.io/npm/v/angular2-template-loader.svg
227
229
  [riot-npm]: https://img.shields.io/npm/v/riot-tag-loader.svg
228
230
 
@@ -262,15 +264,15 @@ Contributions go far beyond pull requests and commits. Although we love giving y
262
264
  * Adding unit, or functional tests
263
265
  * Triaging GitHub issues -- especially determining whether an issue still persists or is reproducible.
264
266
  * [Searching #webpack on twitter](https://twitter.com/search?q=webpack) and helping someone else who needs help
265
- * Teaching others how to contribute to one of the many webpack repo's!
266
- * [Blogging, speaking about, or creating tutorials](https://github.com/webpack-contrib/awesome-webpack) about one of webpack's many features.
267
+ * Teaching others how to contribute to one of the many webpack's repos!
268
+ * [Blogging, speaking about, or creating tutorials](https://github.com/webpack-contrib/awesome-webpack) about one of webpack's many features.
267
269
  * Helping others in our webpack [gitter channel](https://gitter.im/webpack/webpack).
268
270
 
269
- If you are worried or don't know where to start, you can **always** reach out to [Sean Larkin (@TheLarkInn) on Twitter](https://twitter.com/thelarkinn) or simply submit an issue and a maintainer can help give you guidance!
271
+ If you are worried or don't know where to start, you can **always** reach out to [Sean Larkin (@TheLarkInn) on Twitter](https://twitter.com/thelarkinn) or simply submit an issue and a maintainer can help give you guidance!
270
272
 
271
- We have also started a series on our [Medium Publication](https://medium.com/webpack) called [The Contributor's Guide to webpack](https://medium.com/webpack/contributors-guide/home). We welcome you to read it and post any questions or responses if you still need help.
273
+ We have also started a series on our [Medium Publication](https://medium.com/webpack) called [The Contributor's Guide to webpack](https://medium.com/webpack/contributors-guide/home). We welcome you to read it and post any questions or responses if you still need help.
272
274
 
273
- _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!!!
275
+ _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!!!
274
276
 
275
277
  <h3 align="center">Creating your own plugins and loaders</h3>
276
278
 
@@ -280,9 +282,9 @@ If you create a loader or plugin, we would <3 for you to open source it, and put
280
282
 
281
283
  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!
282
284
 
283
- 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!!
285
+ 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!!
284
286
 
285
- If you want to discuss something or just need help, [here is our Gitter room](https://gitter.im/webpack/webpack) where there are always individuals looking to help out!
287
+ If you want to discuss something or just need help, [here is our Gitter room](https://gitter.im/webpack/webpack) where there are always individuals looking to help out!
286
288
 
287
289
  If you are still having difficulty, we would love for you to post
288
290
  a question to [StackOverflow with the webpack tag](https://stackoverflow.com/tags/webpack). It is much easier to answer questions that include your webpack.config.js and relevant files! So if you can provide them, we'd be extremely grateful (and more likely to help you find the answer!)
package/bin/webpack.js CHANGED
@@ -364,7 +364,8 @@ yargs.parse(process.argv.slice(2), (err, argv, output) => {
364
364
  lastHash = null;
365
365
  console.error(err.stack || err);
366
366
  if(err.details) console.error(err.details);
367
- process.exit(1); // eslint-disable-line
367
+ process.exitCode = 1;
368
+ return;
368
369
  }
369
370
  if(outputOptions.json) {
370
371
  process.stdout.write(JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n");
package/hot/signal.js CHANGED
@@ -24,6 +24,7 @@ if(module.hot) {
24
24
  require("./log-apply-result")(updatedModules, renewedModules);
25
25
 
26
26
  checkForUpdate(true);
27
+ return null;
27
28
  });
28
29
  }).catch(function(err) {
29
30
  var status = module.hot.status();
@@ -47,10 +47,12 @@ class BannerPlugin {
47
47
  filename = filename.substr(0, querySplit);
48
48
  }
49
49
 
50
- if(filename.indexOf("/") < 0) {
50
+ const lastSlashIndex = filename.lastIndexOf("/");
51
+
52
+ if(lastSlashIndex === -1) {
51
53
  basename = filename;
52
54
  } else {
53
- basename = filename.substr(filename.lastIndexOf("/") + 1);
55
+ basename = filename.substr(lastSlashIndex + 1);
54
56
  }
55
57
 
56
58
  const comment = compilation.getPath(banner, {
package/lib/Chunk.js CHANGED
@@ -404,14 +404,14 @@ class Chunk {
404
404
  return this.addMultiplierAndOverhead(integratedModulesSize, options);
405
405
  }
406
406
 
407
- getChunkMaps(includeEntries, realHash) {
407
+ getChunkMaps(includeInitial, realHash) {
408
408
  const chunksProcessed = [];
409
409
  const chunkHashMap = {};
410
410
  const chunkNameMap = {};
411
411
  (function addChunk(chunk) {
412
412
  if(chunksProcessed.indexOf(chunk) >= 0) return;
413
413
  chunksProcessed.push(chunk);
414
- if(!chunk.hasRuntime() || includeEntries) {
414
+ if(!chunk.isInitial() || includeInitial) {
415
415
  chunkHashMap[chunk.id] = realHash ? chunk.hash : chunk.renderedHash;
416
416
  if(chunk.name)
417
417
  chunkNameMap[chunk.id] = chunk.name;
@@ -34,7 +34,7 @@ function byId(a, b) {
34
34
 
35
35
  function iterationBlockVariable(variables, fn) {
36
36
  for(let indexVariable = 0; indexVariable < variables.length; indexVariable++) {
37
- let varDep = variables[indexVariable].dependencies;
37
+ const varDep = variables[indexVariable].dependencies;
38
38
  for(let indexVDep = 0; indexVDep < varDep.length; indexVDep++) {
39
39
  fn(varDep[indexVDep]);
40
40
  }
@@ -116,8 +116,8 @@ class Compilation extends Tapable {
116
116
  cacheModule.disconnect();
117
117
  this._modules[identifier] = cacheModule;
118
118
  this.modules.push(cacheModule);
119
- cacheModule.errors.forEach(err => this.errors.push(err), this);
120
- cacheModule.warnings.forEach(err => this.warnings.push(err), this);
119
+ cacheModule.errors.forEach(err => this.errors.push(err));
120
+ cacheModule.warnings.forEach(err => this.warnings.push(err));
121
121
  return cacheModule;
122
122
  }
123
123
  }
@@ -300,9 +300,7 @@ class Compilation extends Tapable {
300
300
  iterationDependencies(dependencies);
301
301
 
302
302
  if(_this.profile) {
303
- if(!module.profile) {
304
- module.profile = {};
305
- }
303
+ module.profile = module.profile || {};
306
304
  const time = Date.now() - start;
307
305
  if(!module.profile.dependencies || time > module.profile.dependencies) {
308
306
  module.profile.dependencies = time;
@@ -572,112 +570,111 @@ class Compilation extends Tapable {
572
570
  }
573
571
 
574
572
  seal(callback) {
575
- const self = this;
576
- self.applyPlugins0("seal");
577
- self.nextFreeModuleIndex = 0;
578
- self.nextFreeModuleIndex2 = 0;
579
- self.preparedChunks.forEach(preparedChunk => {
573
+ this.applyPlugins0("seal");
574
+ this.nextFreeModuleIndex = 0;
575
+ this.nextFreeModuleIndex2 = 0;
576
+ this.preparedChunks.forEach(preparedChunk => {
580
577
  const module = preparedChunk.module;
581
- const chunk = self.addChunk(preparedChunk.name, module);
582
- const entrypoint = self.entrypoints[chunk.name] = new Entrypoint(chunk.name);
578
+ const chunk = this.addChunk(preparedChunk.name, module);
579
+ const entrypoint = this.entrypoints[chunk.name] = new Entrypoint(chunk.name);
583
580
  entrypoint.unshiftChunk(chunk);
584
581
 
585
582
  chunk.addModule(module);
586
583
  module.addChunk(chunk);
587
584
  chunk.entryModule = module;
588
- self.assignIndex(module);
589
- self.assignDepth(module);
585
+ this.assignIndex(module);
586
+ this.assignDepth(module);
590
587
  });
591
- self.processDependenciesBlocksForChunks(self.chunks.slice());
592
- self.sortModules(self.modules);
593
- self.applyPlugins0("optimize");
588
+ this.processDependenciesBlocksForChunks(this.chunks.slice());
589
+ this.sortModules(this.modules);
590
+ this.applyPlugins0("optimize");
594
591
 
595
- while(self.applyPluginsBailResult1("optimize-modules-basic", self.modules) ||
596
- self.applyPluginsBailResult1("optimize-modules", self.modules) ||
597
- self.applyPluginsBailResult1("optimize-modules-advanced", self.modules)) { /* empty */ }
598
- self.applyPlugins1("after-optimize-modules", self.modules);
592
+ while(this.applyPluginsBailResult1("optimize-modules-basic", this.modules) ||
593
+ this.applyPluginsBailResult1("optimize-modules", this.modules) ||
594
+ this.applyPluginsBailResult1("optimize-modules-advanced", this.modules)) { /* empty */ }
595
+ this.applyPlugins1("after-optimize-modules", this.modules);
599
596
 
600
- while(self.applyPluginsBailResult1("optimize-chunks-basic", self.chunks) ||
601
- self.applyPluginsBailResult1("optimize-chunks", self.chunks) ||
602
- self.applyPluginsBailResult1("optimize-chunks-advanced", self.chunks)) { /* empty */ }
603
- self.applyPlugins1("after-optimize-chunks", self.chunks);
597
+ while(this.applyPluginsBailResult1("optimize-chunks-basic", this.chunks) ||
598
+ this.applyPluginsBailResult1("optimize-chunks", this.chunks) ||
599
+ this.applyPluginsBailResult1("optimize-chunks-advanced", this.chunks)) { /* empty */ }
600
+ this.applyPlugins1("after-optimize-chunks", this.chunks);
604
601
 
605
- self.applyPluginsAsyncSeries("optimize-tree", self.chunks, self.modules, function sealPart2(err) {
602
+ this.applyPluginsAsyncSeries("optimize-tree", this.chunks, this.modules, (err) => {
606
603
  if(err) {
607
604
  return callback(err);
608
605
  }
609
606
 
610
- self.applyPlugins2("after-optimize-tree", self.chunks, self.modules);
607
+ this.applyPlugins2("after-optimize-tree", this.chunks, this.modules);
611
608
 
612
- while(self.applyPluginsBailResult("optimize-chunk-modules-basic", self.chunks, self.modules) ||
613
- self.applyPluginsBailResult("optimize-chunk-modules", self.chunks, self.modules) ||
614
- self.applyPluginsBailResult("optimize-chunk-modules-advanced", self.chunks, self.modules)) { /* empty */ }
615
- self.applyPlugins2("after-optimize-chunk-modules", self.chunks, self.modules);
609
+ while(this.applyPluginsBailResult("optimize-chunk-modules-basic", this.chunks, this.modules) ||
610
+ this.applyPluginsBailResult("optimize-chunk-modules", this.chunks, this.modules) ||
611
+ this.applyPluginsBailResult("optimize-chunk-modules-advanced", this.chunks, this.modules)) { /* empty */ }
612
+ this.applyPlugins2("after-optimize-chunk-modules", this.chunks, this.modules);
616
613
 
617
- const shouldRecord = self.applyPluginsBailResult("should-record") !== false;
614
+ const shouldRecord = this.applyPluginsBailResult("should-record") !== false;
618
615
 
619
- self.applyPlugins2("revive-modules", self.modules, self.records);
620
- self.applyPlugins1("optimize-module-order", self.modules);
621
- self.applyPlugins1("advanced-optimize-module-order", self.modules);
622
- self.applyPlugins1("before-module-ids", self.modules);
623
- self.applyPlugins1("module-ids", self.modules);
624
- self.applyModuleIds();
625
- self.applyPlugins1("optimize-module-ids", self.modules);
626
- self.applyPlugins1("after-optimize-module-ids", self.modules);
616
+ this.applyPlugins2("revive-modules", this.modules, this.records);
617
+ this.applyPlugins1("optimize-module-order", this.modules);
618
+ this.applyPlugins1("advanced-optimize-module-order", this.modules);
619
+ this.applyPlugins1("before-module-ids", this.modules);
620
+ this.applyPlugins1("module-ids", this.modules);
621
+ this.applyModuleIds();
622
+ this.applyPlugins1("optimize-module-ids", this.modules);
623
+ this.applyPlugins1("after-optimize-module-ids", this.modules);
627
624
 
628
- self.sortItemsWithModuleIds();
625
+ this.sortItemsWithModuleIds();
629
626
 
630
- self.applyPlugins2("revive-chunks", self.chunks, self.records);
631
- self.applyPlugins1("optimize-chunk-order", self.chunks);
632
- self.applyPlugins1("before-chunk-ids", self.chunks);
633
- self.applyChunkIds();
634
- self.applyPlugins1("optimize-chunk-ids", self.chunks);
635
- self.applyPlugins1("after-optimize-chunk-ids", self.chunks);
627
+ this.applyPlugins2("revive-chunks", this.chunks, this.records);
628
+ this.applyPlugins1("optimize-chunk-order", this.chunks);
629
+ this.applyPlugins1("before-chunk-ids", this.chunks);
630
+ this.applyChunkIds();
631
+ this.applyPlugins1("optimize-chunk-ids", this.chunks);
632
+ this.applyPlugins1("after-optimize-chunk-ids", this.chunks);
636
633
 
637
- self.sortItemsWithChunkIds();
634
+ this.sortItemsWithChunkIds();
638
635
 
639
636
  if(shouldRecord)
640
- self.applyPlugins2("record-modules", self.modules, self.records);
637
+ this.applyPlugins2("record-modules", this.modules, this.records);
641
638
  if(shouldRecord)
642
- self.applyPlugins2("record-chunks", self.chunks, self.records);
639
+ this.applyPlugins2("record-chunks", this.chunks, this.records);
643
640
 
644
- self.applyPlugins0("before-hash");
645
- self.createHash();
646
- self.applyPlugins0("after-hash");
641
+ this.applyPlugins0("before-hash");
642
+ this.createHash();
643
+ this.applyPlugins0("after-hash");
647
644
 
648
645
  if(shouldRecord)
649
- self.applyPlugins1("record-hash", self.records);
646
+ this.applyPlugins1("record-hash", this.records);
650
647
 
651
- self.applyPlugins0("before-module-assets");
652
- self.createModuleAssets();
653
- if(self.applyPluginsBailResult("should-generate-chunk-assets") !== false) {
654
- self.applyPlugins0("before-chunk-assets");
655
- self.createChunkAssets();
648
+ this.applyPlugins0("before-module-assets");
649
+ this.createModuleAssets();
650
+ if(this.applyPluginsBailResult("should-generate-chunk-assets") !== false) {
651
+ this.applyPlugins0("before-chunk-assets");
652
+ this.createChunkAssets();
656
653
  }
657
- self.applyPlugins1("additional-chunk-assets", self.chunks);
658
- self.summarizeDependencies();
654
+ this.applyPlugins1("additional-chunk-assets", this.chunks);
655
+ this.summarizeDependencies();
659
656
  if(shouldRecord)
660
- self.applyPlugins2("record", self, self.records);
657
+ this.applyPlugins2("record", this, this.records);
661
658
 
662
- self.applyPluginsAsync("additional-assets", err => {
659
+ this.applyPluginsAsync("additional-assets", err => {
663
660
  if(err) {
664
661
  return callback(err);
665
662
  }
666
- self.applyPluginsAsync("optimize-chunk-assets", self.chunks, err => {
663
+ this.applyPluginsAsync("optimize-chunk-assets", this.chunks, err => {
667
664
  if(err) {
668
665
  return callback(err);
669
666
  }
670
- self.applyPlugins1("after-optimize-chunk-assets", self.chunks);
671
- self.applyPluginsAsync("optimize-assets", self.assets, err => {
667
+ this.applyPlugins1("after-optimize-chunk-assets", this.chunks);
668
+ this.applyPluginsAsync("optimize-assets", this.assets, err => {
672
669
  if(err) {
673
670
  return callback(err);
674
671
  }
675
- self.applyPlugins1("after-optimize-assets", self.assets);
676
- if(self.applyPluginsBailResult("need-additional-seal")) {
677
- self.unseal();
678
- return self.seal(callback);
672
+ this.applyPlugins1("after-optimize-assets", this.assets);
673
+ if(this.applyPluginsBailResult("need-additional-seal")) {
674
+ this.unseal();
675
+ return this.seal(callback);
679
676
  }
680
- return self.applyPluginsAsync("after-seal", callback);
677
+ return this.applyPluginsAsync("after-seal", callback);
681
678
  });
682
679
  });
683
680
  });
@@ -685,11 +682,7 @@ class Compilation extends Tapable {
685
682
  }
686
683
 
687
684
  sortModules(modules) {
688
- modules.sort((a, b) => {
689
- if(a.index < b.index) return -1;
690
- if(a.index > b.index) return 1;
691
- return 0;
692
- });
685
+ modules.sort(byId);
693
686
  }
694
687
 
695
688
  reportDependencyErrorsAndWarnings(module, blocks) {
@@ -1097,9 +1090,9 @@ class Compilation extends Tapable {
1097
1090
  }
1098
1091
 
1099
1092
  applyModuleIds() {
1100
- let unusedIds = [];
1093
+ const unusedIds = [];
1101
1094
  let nextFreeModuleId = 0;
1102
- let usedIds = [];
1095
+ const usedIds = [];
1103
1096
  // TODO consider Map when performance has improved https://gist.github.com/sokra/234c077e1299b7369461f1708519c392
1104
1097
  const usedIdMap = Object.create(null);
1105
1098
  if(this.usedModuleIds) {
@@ -1218,14 +1211,12 @@ class Compilation extends Tapable {
1218
1211
  sortItemsWithChunkIds() {
1219
1212
  this.chunks.sort(byId);
1220
1213
 
1221
- const modules = this.modules;
1222
- for(let indexModule = 0; indexModule < modules.length; indexModule++) {
1223
- modules[indexModule].sortItems(true);
1214
+ for(let indexModule = 0; indexModule < this.modules.length; indexModule++) {
1215
+ this.modules[indexModule].sortItems(true);
1224
1216
  }
1225
1217
 
1226
- const chunks = this.chunks;
1227
- for(let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
1228
- chunks[indexChunk].sortItems();
1218
+ for(let indexChunk = 0; indexChunk < this.chunks.length; indexChunk++) {
1219
+ this.chunks[indexChunk].sortItems();
1229
1220
  }
1230
1221
 
1231
1222
  const byMessage = (a, b) => {
@@ -1253,18 +1244,16 @@ class Compilation extends Tapable {
1253
1244
  this.contextDependencies = [];
1254
1245
  this.missingDependencies = [];
1255
1246
 
1256
- const children = this.children;
1257
- for(let indexChildren = 0; indexChildren < children.length; indexChildren++) {
1258
- const child = children[indexChildren];
1247
+ for(let indexChildren = 0; indexChildren < this.children.length; indexChildren++) {
1248
+ const child = this.children[indexChildren];
1259
1249
 
1260
1250
  this.fileDependencies = this.fileDependencies.concat(child.fileDependencies);
1261
1251
  this.contextDependencies = this.contextDependencies.concat(child.contextDependencies);
1262
1252
  this.missingDependencies = this.missingDependencies.concat(child.missingDependencies);
1263
1253
  }
1264
1254
 
1265
- const modules = this.modules;
1266
- for(let indexModule = 0; indexModule < modules.length; indexModule++) {
1267
- const module = modules[indexModule];
1255
+ for(let indexModule = 0; indexModule < this.modules.length; indexModule++) {
1256
+ const module = this.modules[indexModule];
1268
1257
 
1269
1258
  if(module.fileDependencies) {
1270
1259
  const fileDependencies = module.fileDependencies;
@@ -7,6 +7,9 @@
7
7
 
8
8
  const DefinePlugin = require("./DefinePlugin");
9
9
 
10
+ const needsEnvVarFix = ["8", "9"].indexOf(process.versions.node.split(".")[0]) >= 0 &&
11
+ process.platform === "win32";
12
+
10
13
  class EnvironmentPlugin {
11
14
  constructor(keys) {
12
15
  if(Array.isArray(keys)) {
@@ -23,6 +26,13 @@ class EnvironmentPlugin {
23
26
 
24
27
  apply(compiler) {
25
28
  const definitions = this.keys.reduce((defs, key) => {
29
+ // TODO remove once the fix has made its way into Node 8.
30
+ // Work around https://github.com/nodejs/node/pull/18463,
31
+ // affecting Node 8 & 9 by performing an OS-level
32
+ // operation that always succeeds before reading
33
+ // environment variables:
34
+ if(needsEnvVarFix) require("os").cpus();
35
+
26
36
  const value = process.env[key] !== undefined ? process.env[key] : this.defaultValues[key];
27
37
 
28
38
  if(value === undefined) {
@@ -29,6 +29,7 @@ class JsonpMainTemplatePlugin {
29
29
  const chunkMaps = chunk.getChunkMaps();
30
30
  const crossOriginLoading = this.outputOptions.crossOriginLoading;
31
31
  const chunkLoadTimeout = this.outputOptions.chunkLoadTimeout;
32
+ const jsonpScriptType = this.outputOptions.jsonpScriptType;
32
33
  const scriptSrcPath = this.applyPluginsWaterfall("asset-path", JSON.stringify(chunkFilename), {
33
34
  hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
34
35
  hashWithLength: length => `" + ${this.renderCurrentHashCode(hash, length)} + "`,
@@ -48,7 +49,7 @@ class JsonpMainTemplatePlugin {
48
49
  });
49
50
  return this.asString([
50
51
  "var script = document.createElement('script');",
51
- "script.type = 'text/javascript';",
52
+ `script.type = ${JSON.stringify(jsonpScriptType)};`,
52
53
  "script.charset = 'utf-8';",
53
54
  "script.async = true;",
54
55
  `script.timeout = ${chunkLoadTimeout};`,
@@ -99,7 +99,9 @@ module.exports = class MainTemplate extends Template {
99
99
  });
100
100
  this.plugin("require-extensions", (source, chunk, hash) => {
101
101
  const buf = [];
102
- if(chunk.chunks.length > 0) {
102
+ const chunkMaps = chunk.getChunkMaps();
103
+ // Check if there are non initial chunks which need to be imported using require-ensure
104
+ if(Object.keys(chunkMaps.hash).length) {
103
105
  buf.push("// This file contains only the entry chunk.");
104
106
  buf.push("// The chunk loading function for additional chunks");
105
107
  buf.push(`${this.requireFn}.e = function requireEnsure(chunkId) {`);
@@ -7,12 +7,12 @@
7
7
  class NoEmitOnErrorsPlugin {
8
8
  apply(compiler) {
9
9
  compiler.plugin("should-emit", (compilation) => {
10
- if(compilation.errors.length > 0)
10
+ if(compilation.getStats().hasErrors())
11
11
  return false;
12
12
  });
13
13
  compiler.plugin("compilation", (compilation) => {
14
14
  compilation.plugin("should-record", () => {
15
- if(compilation.errors.length > 0)
15
+ if(compilation.getStats().hasErrors())
16
16
  return false;
17
17
  });
18
18
  });
@@ -133,7 +133,9 @@ class NormalModuleFactory extends Tapable {
133
133
  try {
134
134
  loaders.forEach(item => {
135
135
  if(typeof item.options === "string" && /^\?/.test(item.options)) {
136
- item.options = this.ruleSet.findOptionsByIdent(item.options.substr(1));
136
+ const ident = item.options.substr(1);
137
+ item.options = this.ruleSet.findOptionsByIdent(ident);
138
+ item.ident = ident;
137
139
  }
138
140
  });
139
141
  } catch(e) {
package/lib/Parser.js CHANGED
@@ -174,6 +174,15 @@ class Parser extends Tapable {
174
174
  res.setNumber(left.number / right.number);
175
175
  res.setRange(expr.range);
176
176
  return res;
177
+ } else if(expr.operator === "**") {
178
+ left = this.evaluateExpression(expr.left);
179
+ right = this.evaluateExpression(expr.right);
180
+ if(!left || !right) return;
181
+ if(!left.isNumber() || !right.isNumber()) return;
182
+ res = new BasicEvaluatedExpression();
183
+ res.setNumber(Math.pow(left.number, right.number));
184
+ res.setRange(expr.range);
185
+ return res;
177
186
  } else if(expr.operator === "==" || expr.operator === "===") {
178
187
  left = this.evaluateExpression(expr.left);
179
188
  right = this.evaluateExpression(expr.right);
@@ -200,6 +209,60 @@ class Parser extends Tapable {
200
209
  } else if(left.isBoolean() && right.isBoolean()) {
201
210
  return res.setBoolean(left.bool !== right.bool);
202
211
  }
212
+ } else if(expr.operator === "&") {
213
+ left = this.evaluateExpression(expr.left);
214
+ right = this.evaluateExpression(expr.right);
215
+ if(!left || !right) return;
216
+ if(!left.isNumber() || !right.isNumber()) return;
217
+ res = new BasicEvaluatedExpression();
218
+ res.setNumber(left.number & right.number);
219
+ res.setRange(expr.range);
220
+ return res;
221
+ } else if(expr.operator === "|") {
222
+ left = this.evaluateExpression(expr.left);
223
+ right = this.evaluateExpression(expr.right);
224
+ if(!left || !right) return;
225
+ if(!left.isNumber() || !right.isNumber()) return;
226
+ res = new BasicEvaluatedExpression();
227
+ res.setNumber(left.number | right.number);
228
+ res.setRange(expr.range);
229
+ return res;
230
+ } else if(expr.operator === "^") {
231
+ left = this.evaluateExpression(expr.left);
232
+ right = this.evaluateExpression(expr.right);
233
+ if(!left || !right) return;
234
+ if(!left.isNumber() || !right.isNumber()) return;
235
+ res = new BasicEvaluatedExpression();
236
+ res.setNumber(left.number ^ right.number);
237
+ res.setRange(expr.range);
238
+ return res;
239
+ } else if(expr.operator === ">>>") {
240
+ left = this.evaluateExpression(expr.left);
241
+ right = this.evaluateExpression(expr.right);
242
+ if(!left || !right) return;
243
+ if(!left.isNumber() || !right.isNumber()) return;
244
+ res = new BasicEvaluatedExpression();
245
+ res.setNumber(left.number >>> right.number);
246
+ res.setRange(expr.range);
247
+ return res;
248
+ } else if(expr.operator === ">>") {
249
+ left = this.evaluateExpression(expr.left);
250
+ right = this.evaluateExpression(expr.right);
251
+ if(!left || !right) return;
252
+ if(!left.isNumber() || !right.isNumber()) return;
253
+ res = new BasicEvaluatedExpression();
254
+ res.setNumber(left.number >> right.number);
255
+ res.setRange(expr.range);
256
+ return res;
257
+ } else if(expr.operator === "<<") {
258
+ left = this.evaluateExpression(expr.left);
259
+ right = this.evaluateExpression(expr.right);
260
+ if(!left || !right) return;
261
+ if(!left.isNumber() || !right.isNumber()) return;
262
+ res = new BasicEvaluatedExpression();
263
+ res.setNumber(left.number << right.number);
264
+ res.setRange(expr.range);
265
+ return res;
203
266
  }
204
267
  });
205
268
  this.plugin("evaluate UnaryExpression", function(expr) {
@@ -242,6 +305,14 @@ class Parser extends Tapable {
242
305
  } else if(argument.isNumber()) {
243
306
  return new BasicEvaluatedExpression().setBoolean(!argument.number).setRange(expr.range);
244
307
  }
308
+ } else if(expr.operator === "~") {
309
+ const argument = this.evaluateExpression(expr.argument);
310
+ if(!argument) return;
311
+ if(!argument.isNumber()) return;
312
+ const res = new BasicEvaluatedExpression();
313
+ res.setNumber(~argument.number);
314
+ res.setRange(expr.range);
315
+ return res;
245
316
  }
246
317
  });
247
318
  this.plugin("evaluate typeof undefined", function(expr) {
@@ -1047,6 +1118,14 @@ class Parser extends Tapable {
1047
1118
  }
1048
1119
 
1049
1120
  walkNewExpression(expression) {
1121
+ const callee = this.evaluateExpression(expression.callee);
1122
+ if(callee.isIdentifier()) {
1123
+ const result = this.applyPluginsBailResult("new " + callee.identifier, expression);
1124
+ if(result === true) {
1125
+ return;
1126
+ }
1127
+ }
1128
+
1050
1129
  this.walkExpression(expression.callee);
1051
1130
  if(expression.arguments)
1052
1131
  this.walkExpressions(expression.arguments);
package/lib/Stats.js CHANGED
@@ -50,11 +50,13 @@ class Stats {
50
50
  }
51
51
 
52
52
  hasWarnings() {
53
- return this.compilation.warnings.length > 0;
53
+ return this.compilation.warnings.length > 0 ||
54
+ this.compilation.children.some(child => child.getStats().hasWarnings());
54
55
  }
55
56
 
56
57
  hasErrors() {
57
- return this.compilation.errors.length > 0;
58
+ return this.compilation.errors.length > 0 ||
59
+ this.compilation.children.some(child => child.getStats().hasErrors());
58
60
  }
59
61
 
60
62
  // remove a prefixed "!" that can be specified to reverse sort order
@@ -60,6 +60,10 @@ const replacePathVariables = (path, data) => {
60
60
  const chunkHash = chunk && (chunk.renderedHash || chunk.hash);
61
61
  const chunkHashWithLength = chunk && chunk.hashWithLength;
62
62
 
63
+ if(typeof path === "function") {
64
+ path = path(data);
65
+ }
66
+
63
67
  if(data.noChunkHash && REGEXP_CHUNKHASH_FOR_TEST.test(path)) {
64
68
  throw new Error(`Cannot use [chunkhash] for chunk in '${path}' (use [hash] instead)`);
65
69
  }
@@ -101,9 +105,9 @@ class TemplatedPathPlugin {
101
105
  const outputOptions = this.outputOptions;
102
106
  const chunkFilename = outputOptions.chunkFilename || outputOptions.filename;
103
107
  if(REGEXP_CHUNKHASH_FOR_TEST.test(chunkFilename))
104
- hash.update(JSON.stringify(chunk.getChunkMaps(true, true).hash));
108
+ hash.update(JSON.stringify(chunk.getChunkMaps(false, true).hash));
105
109
  if(REGEXP_NAME_FOR_TEST.test(chunkFilename))
106
- hash.update(JSON.stringify(chunk.getChunkMaps(true, true).name));
110
+ hash.update(JSON.stringify(chunk.getChunkMaps(false, true).name));
107
111
  });
108
112
  });
109
113
  }
@@ -61,6 +61,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
61
61
  this.set("output.hotUpdateChunkFilename", "[id].[hash].hot-update.js");
62
62
  this.set("output.hotUpdateMainFilename", "[hash].hot-update.json");
63
63
  this.set("output.crossOriginLoading", false);
64
+ this.set("output.jsonpScriptType", "text/javascript");
64
65
  this.set("output.chunkLoadTimeout", 120000);
65
66
  this.set("output.hashFunction", "md5");
66
67
  this.set("output.hashDigest", "hex");
@@ -6,9 +6,11 @@
6
6
 
7
7
  const ExternalsPlugin = require("../ExternalsPlugin");
8
8
 
9
+ const builtins = require("module").builtinModules || Object.keys(process.binding("natives"));
10
+
9
11
  class NodeTargetPlugin {
10
12
  apply(compiler) {
11
- new ExternalsPlugin("commonjs", Object.keys(process.binding("natives"))).apply(compiler);
13
+ new ExternalsPlugin("commonjs", builtins).apply(compiler);
12
14
  }
13
15
  }
14
16
 
@@ -143,6 +143,7 @@ function getPathInAst(ast, node) {
143
143
  }
144
144
 
145
145
  function enterNode(n) {
146
+ if(!n) return undefined;
146
147
  const r = n.range;
147
148
  if(r) {
148
149
  if(r[0] <= nr[0] && r[1] >= nr[1]) {
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "3.10.0",
3
+ "version": "3.11.0",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
6
6
  "dependencies": {
7
7
  "acorn": "^5.0.0",
8
8
  "acorn-dynamic-import": "^2.0.0",
9
- "ajv": "^5.1.5",
10
- "ajv-keywords": "^2.0.0",
9
+ "ajv": "^6.1.0",
10
+ "ajv-keywords": "^3.1.0",
11
11
  "async": "^2.1.2",
12
12
  "enhanced-resolve": "^3.4.0",
13
13
  "escope": "^3.6.0",
@@ -54,7 +54,6 @@
54
54
  "lodash": "^4.17.4",
55
55
  "mocha": "^3.2.0",
56
56
  "mocha-lcov-reporter": "^1.0.0",
57
- "nsp": "^2.6.1",
58
57
  "raw-loader": "~0.5.0",
59
58
  "react": "^15.2.1",
60
59
  "react-dom": "^15.2.1",
@@ -95,13 +94,13 @@
95
94
  "test:unit": "mocha test/*.unittest.js --max-old-space-size=4096 --harmony --trace-deprecation --check-leaks",
96
95
  "travis:integration": "npm run cover:init && npm run cover:integration && npm run cover:report-min",
97
96
  "travis:unit": "npm run cover:init && npm run cover:unit && npm run cover:report-min",
98
- "travis:lint": "npm run lint-files && npm run nsp",
97
+ "travis:lint": "npm run lint-files",
99
98
  "travis:benchmark": "npm run benchmark",
100
99
  "appveyor:integration": "npm run cover:init && npm run cover:integration && npm run cover:report-min",
101
100
  "appveyor:unit": "npm run cover:init && npm run cover:unit && npm run cover:report-min",
102
101
  "appveyor:benchmark": "npm run benchmark",
103
102
  "circleci:test": "node node_modules/mocha/bin/mocha --max-old-space-size=4096 --harmony --trace-deprecation test/*.test.js test/*.unittest.js",
104
- "circleci:lint": "npm run lint-files && npm run nsp",
103
+ "circleci:lint": "npm run lint-files",
105
104
  "build:examples": "cd examples && node buildAll.js",
106
105
  "pretest": "npm run lint-files",
107
106
  "lint-files": "npm run lint && npm run beautify-lint && npm run schema-lint",
@@ -109,7 +108,6 @@
109
108
  "fix": "npm run lint -- --fix",
110
109
  "beautify-lint": "beautify-lint \"lib/**/*.js\" \"hot/**/*.js\" \"bin/**/*.js\" \"benchmark/*.js\" \"test/*.js\"",
111
110
  "schema-lint": "mocha test/*.lint.js --opts test/lint-mocha.opts",
112
- "nsp": "nsp check --output summary",
113
111
  "benchmark": "mocha --max-old-space-size=4096 --harmony --trace-deprecation test/*.benchmark.js -R spec",
114
112
  "cover": "npm run cover:init && npm run cover:all && npm run cover:report",
115
113
  "cover:init": "rimraf coverage",
@@ -296,7 +296,14 @@
296
296
  },
297
297
  "chunkFilename": {
298
298
  "description": "The filename of non-entry chunks as relative path inside the `output.path` directory.",
299
- "type": "string",
299
+ "anyOf": [
300
+ {
301
+ "type": "string"
302
+ },
303
+ {
304
+ "instanceof": "Function"
305
+ }
306
+ ],
300
307
  "absolutePath": false
301
308
  },
302
309
  "crossOriginLoading": {
@@ -307,6 +314,13 @@
307
314
  "use-credentials"
308
315
  ]
309
316
  },
317
+ "jsonpScriptType": {
318
+ "description": "This option enables loading async chunks via a custom script type, such as script type=\"module\"",
319
+ "enum": [
320
+ "text/javascript",
321
+ "module"
322
+ ]
323
+ },
310
324
  "chunkLoadTimeout": {
311
325
  "description": "Number of milliseconds before chunk request expires",
312
326
  "type": "number"
@@ -348,7 +362,14 @@
348
362
  },
349
363
  "filename": {
350
364
  "description": "Specifies the name of each output file on disk. You must **not** specify an absolute path here! The `output.path` option determines the location on disk the files are written to, filename is used solely for naming the individual files.",
351
- "type": "string",
365
+ "anyOf": [
366
+ {
367
+ "type": "string"
368
+ },
369
+ {
370
+ "instanceof": "Function"
371
+ }
372
+ ],
352
373
  "absolutePath": false
353
374
  },
354
375
  "hashDigest": {
@@ -376,7 +397,14 @@
376
397
  },
377
398
  "hotUpdateChunkFilename": {
378
399
  "description": "The filename of the Hot Update Chunks. They are inside the output.path directory.",
379
- "type": "string",
400
+ "anyOf": [
401
+ {
402
+ "type": "string"
403
+ },
404
+ {
405
+ "instanceof": "Function"
406
+ }
407
+ ],
380
408
  "absolutePath": false
381
409
  },
382
410
  "hotUpdateFunction": {
@@ -385,7 +413,14 @@
385
413
  },
386
414
  "hotUpdateMainFilename": {
387
415
  "description": "The filename of the Hot Update Main File. It is inside the `output.path` directory.",
388
- "type": "string",
416
+ "anyOf": [
417
+ {
418
+ "type": "string"
419
+ },
420
+ {
421
+ "instanceof": "Function"
422
+ }
423
+ ],
389
424
  "absolutePath": false
390
425
  },
391
426
  "jsonpFunction": {
@@ -464,7 +499,14 @@
464
499
  },
465
500
  "publicPath": {
466
501
  "description": "The `publicPath` specifies the public URL address of the output files when referenced in a browser.",
467
- "type": "string"
502
+ "anyOf": [
503
+ {
504
+ "type": "string"
505
+ },
506
+ {
507
+ "instanceof": "Function"
508
+ }
509
+ ]
468
510
  },
469
511
  "sourceMapFilename": {
470
512
  "description": "The filename of the SourceMaps for the JavaScript files. They are inside the `output.path` directory.",
@@ -931,6 +973,10 @@
931
973
  }
932
974
  ]
933
975
  },
976
+ "ident": {
977
+ "description": "Unique loader identifier",
978
+ "type": "string"
979
+ },
934
980
  "query": {
935
981
  "description": "Loader query",
936
982
  "anyOf": [