webpack 4.33.0 → 4.35.2

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.
@@ -558,6 +558,10 @@ export interface RuleSetRule {
558
558
  * Shortcut for use.query
559
559
  */
560
560
  query?: RuleSetQuery;
561
+ /**
562
+ * Match rules with custom resource name
563
+ */
564
+ realResource?: RuleSetConditionOrConditionsAbsolute;
561
565
  /**
562
566
  * Options for the resolver
563
567
  */
@@ -870,6 +874,10 @@ export interface OptimizationSplitChunksOptions {
870
874
  * Sets the name delimiter for created chunks
871
875
  */
872
876
  automaticNameDelimiter?: string;
877
+ /**
878
+ * Sets the max length for the name of a created chunk
879
+ */
880
+ automaticNameMaxLength?: number;
873
881
  /**
874
882
  * Assign modules to a cache group (modules from different cache groups are tried to keep in separate chunks)
875
883
  */
@@ -887,6 +895,10 @@ export interface OptimizationSplitChunksOptions {
887
895
  * Sets the name delimiter for created chunks
888
896
  */
889
897
  automaticNameDelimiter?: string;
898
+ /**
899
+ * Sets the max length for the name of a created chunk
900
+ */
901
+ automaticNameMaxLength?: number;
890
902
  /**
891
903
  * Sets the name prefix for created chunks
892
904
  */
package/hot/dev-server.js CHANGED
@@ -40,10 +40,10 @@ if (module.hot) {
40
40
  "warning",
41
41
  "[HMR] Cannot apply update. Need to do a full reload!"
42
42
  );
43
- log("warning", "[HMR] " + (err.stack || err.message));
43
+ log("warning", "[HMR] " + log.formatError(err));
44
44
  window.location.reload();
45
45
  } else {
46
- log("warning", "[HMR] Update failed: " + (err.stack || err.message));
46
+ log("warning", "[HMR] Update failed: " + log.formatError(err));
47
47
  }
48
48
  });
49
49
  };
package/hot/log.js CHANGED
@@ -45,3 +45,15 @@ module.exports.groupEnd = logGroup(groupEnd);
45
45
  module.exports.setLogLevel = function(level) {
46
46
  logLevel = level;
47
47
  };
48
+
49
+ module.exports.formatError = function(err) {
50
+ var message = err.message;
51
+ var stack = err.stack;
52
+ if (!stack) {
53
+ return message;
54
+ } else if (stack.indexOf(message) < 0) {
55
+ return message + "\n" + stack;
56
+ } else {
57
+ return stack;
58
+ }
59
+ };
@@ -72,12 +72,9 @@ if (module.hot) {
72
72
  "warning",
73
73
  "[HMR] Cannot check for update. Need to do a full reload!"
74
74
  );
75
- log("warning", "[HMR] " + (err.stack || err.message));
75
+ log("warning", "[HMR] " + log.formatError(err));
76
76
  } else {
77
- log(
78
- "warning",
79
- "[HMR] Update check failed: " + (err.stack || err.message)
80
- );
77
+ log("warning", "[HMR] Update check failed: " + log.formatError(err));
81
78
  }
82
79
  });
83
80
  };
package/hot/poll.js CHANGED
@@ -23,13 +23,10 @@ if (module.hot) {
23
23
  var status = module.hot.status();
24
24
  if (["abort", "fail"].indexOf(status) >= 0) {
25
25
  log("warning", "[HMR] Cannot apply update.");
26
- log("warning", "[HMR] " + (err.stack || err.message));
26
+ log("warning", "[HMR] " + log.formatError(err));
27
27
  log("warning", "[HMR] You need to restart the application!");
28
28
  } else {
29
- log(
30
- "warning",
31
- "[HMR] Update failed: " + (err.stack || err.message)
32
- );
29
+ log("warning", "[HMR] Update failed: " + log.formatError(err));
33
30
  }
34
31
  });
35
32
  }
package/hot/signal.js CHANGED
@@ -37,7 +37,7 @@ if (module.hot) {
37
37
  var status = module.hot.status();
38
38
  if (["abort", "fail"].indexOf(status) >= 0) {
39
39
  log("warning", "[HMR] Cannot apply update.");
40
- log("warning", "[HMR] " + (err.stack || err.message));
40
+ log("warning", "[HMR] " + log.formatError(err));
41
41
  log("warning", "[HMR] You need to restart the application!");
42
42
  } else {
43
43
  log("warning", "[HMR] Update failed: " + (err.stack || err.message));
package/lib/ChunkGroup.js CHANGED
@@ -496,18 +496,14 @@ class ChunkGroup {
496
496
  for (const child of chunk._children) {
497
497
  if (!child._parents.has(chunk)) {
498
498
  throw new Error(
499
- `checkConstraints: child missing parent ${chunk.debugId} -> ${
500
- child.debugId
501
- }`
499
+ `checkConstraints: child missing parent ${chunk.debugId} -> ${child.debugId}`
502
500
  );
503
501
  }
504
502
  }
505
503
  for (const parentChunk of chunk._parents) {
506
504
  if (!parentChunk._children.has(chunk)) {
507
505
  throw new Error(
508
- `checkConstraints: parent missing child ${parentChunk.debugId} <- ${
509
- chunk.debugId
510
- }`
506
+ `checkConstraints: parent missing child ${parentChunk.debugId} <- ${chunk.debugId}`
511
507
  );
512
508
  }
513
509
  }
@@ -694,9 +694,7 @@ class Compilation extends Tapable {
694
694
  const factory = this.dependencyFactories.get(dep.constructor);
695
695
  if (factory === undefined) {
696
696
  throw new Error(
697
- `No module factory available for dependency type: ${
698
- dep.constructor.name
699
- }`
697
+ `No module factory available for dependency type: ${dep.constructor.name}`
700
698
  );
701
699
  }
702
700
  let innerMap = dependencies.get(factory);
@@ -958,9 +956,7 @@ class Compilation extends Tapable {
958
956
  const moduleFactory = this.dependencyFactories.get(Dep);
959
957
  if (!moduleFactory) {
960
958
  throw new Error(
961
- `No dependency factory available for this dependency type: ${
962
- dependency.constructor.name
963
- }`
959
+ `No dependency factory available for this dependency type: ${dependency.constructor.name}`
964
960
  );
965
961
  }
966
962
 
@@ -345,9 +345,7 @@ module.exports = class MainTemplate extends Tapable {
345
345
  buf.push("");
346
346
  buf.push("// Object.prototype.hasOwnProperty.call");
347
347
  buf.push(
348
- `${
349
- this.requireFn
350
- }.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };`
348
+ `${this.requireFn}.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };`
351
349
  );
352
350
 
353
351
  const publicPath = this.getPublicPath({
@@ -13,11 +13,21 @@ class ModuleParseError extends WebpackError {
13
13
  * @param {Module} module the errored module
14
14
  * @param {string} source source code
15
15
  * @param {Error&any} err the parse error
16
+ * @param {string[]} loaders the loaders used
16
17
  */
17
- constructor(module, source, err) {
18
+ constructor(module, source, err, loaders) {
18
19
  let message = "Module parse failed: " + err.message;
19
20
  let loc = undefined;
20
- message += "\nYou may need an appropriate loader to handle this file type.";
21
+ if (loaders.length >= 1) {
22
+ message += `\nFile was processed with these loaders:${loaders
23
+ .map(loader => `\n * ${loader}`)
24
+ .join("")}`;
25
+ message +=
26
+ "\nYou may need an additional loader to handle the result of these loaders.";
27
+ } else {
28
+ message +=
29
+ "\nYou may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders";
30
+ }
21
31
  if (
22
32
  err.loc &&
23
33
  typeof err.loc === "object" &&
@@ -28,7 +38,7 @@ class ModuleParseError extends WebpackError {
28
38
  // binary file
29
39
  message += "\n(Source code omitted for this binary file)";
30
40
  } else {
31
- const sourceLines = source.split("\n");
41
+ const sourceLines = source.split(/\r?\n/);
32
42
  const start = Math.max(0, lineNumber - 3);
33
43
  const linesBefore = sourceLines.slice(start, lineNumber - 1);
34
44
  const theLine = sourceLines[lineNumber - 1];
@@ -18,6 +18,18 @@ class MultiWatching {
18
18
  }
19
19
  }
20
20
 
21
+ suspend() {
22
+ for (const watching of this.watchings) {
23
+ watching.suspend();
24
+ }
25
+ }
26
+
27
+ resume() {
28
+ for (const watching of this.watchings) {
29
+ watching.resume();
30
+ }
31
+ }
32
+
21
33
  close(callback) {
22
34
  asyncLib.forEach(
23
35
  this.watchings,
@@ -348,7 +348,6 @@ class NormalModule extends Module {
348
348
  markModuleAsErrored(error) {
349
349
  // Restore build meta from successful build to keep importing state
350
350
  this.buildMeta = Object.assign({}, this._lastSuccessfulBuildMeta);
351
-
352
351
  this.error = error;
353
352
  this.errors.push(this.error);
354
353
  this._source = new RawSource(
@@ -445,7 +444,10 @@ class NormalModule extends Module {
445
444
 
446
445
  const handleParseError = e => {
447
446
  const source = this._source.source();
448
- const error = new ModuleParseError(this, source, e);
447
+ const loaders = this.loaders.map(item =>
448
+ contextify(options.context, item.loader)
449
+ );
450
+ const error = new ModuleParseError(this, source, e, loaders);
449
451
  this.markModuleAsErrored(error);
450
452
  this._initBuildHash(compilation);
451
453
  return callback();
@@ -335,7 +335,11 @@ class NormalModuleFactory extends Tapable {
335
335
  ],
336
336
  (err, results) => {
337
337
  if (err) return callback(err);
338
- loaders = results[0].concat(loaders, results[1], results[2]);
338
+ if (matchResource === undefined) {
339
+ loaders = results[0].concat(loaders, results[1], results[2]);
340
+ } else {
341
+ loaders = results[0].concat(results[1], loaders, results[2]);
342
+ }
339
343
  process.nextTick(() => {
340
344
  const type = settings.type;
341
345
  const resolveOptions = settings.resolve;
@@ -435,9 +439,7 @@ class NormalModuleFactory extends Tapable {
435
439
  err.message +
436
440
  "\n" +
437
441
  "BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders.\n" +
438
- ` You need to specify '${
439
- item.loader
440
- }-loader' instead of '${item.loader}',\n` +
442
+ ` You need to specify '${item.loader}-loader' instead of '${item.loader}',\n` +
441
443
  " see https://webpack.js.org/migrate/3/#automatic-loader-module-name-extension-removed";
442
444
  }
443
445
  callback(err);
@@ -4,8 +4,14 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- const getProperty = (obj, name) => {
8
- name = name.split(".");
7
+ /**
8
+ * Gets the value at path of object
9
+ * @param {object} obj - object to query
10
+ * @param {string} path - query path
11
+ * @returns {any} - if {@param path} requests element from array, then `undefined` will be returned
12
+ */
13
+ const getProperty = (obj, path) => {
14
+ let name = path.split(".");
9
15
  for (let i = 0; i < name.length - 1; i++) {
10
16
  obj = obj[name[i]];
11
17
  if (typeof obj !== "object" || !obj || Array.isArray(obj)) return;
@@ -13,8 +19,15 @@ const getProperty = (obj, name) => {
13
19
  return obj[name.pop()];
14
20
  };
15
21
 
16
- const setProperty = (obj, name, value) => {
17
- name = name.split(".");
22
+ /**
23
+ * Sets the value at path of object. Stops execution, if {@param path} requests element from array to be set
24
+ * @param {object} obj - object to query
25
+ * @param {string} path - query path
26
+ * @param {any} value - value to be set
27
+ * @returns {void}
28
+ */
29
+ const setProperty = (obj, path, value) => {
30
+ let name = path.split(".");
18
31
  for (let i = 0; i < name.length - 1; i++) {
19
32
  if (typeof obj[name[i]] !== "object" && obj[name[i]] !== undefined) return;
20
33
  if (Array.isArray(obj[name[i]])) return;
@@ -24,21 +37,53 @@ const setProperty = (obj, name, value) => {
24
37
  obj[name.pop()] = value;
25
38
  };
26
39
 
40
+ /**
41
+ * @typedef {'call' | 'make' | 'append'} ConfigType
42
+ */
43
+ /**
44
+ * @typedef {(options: object) => any} MakeConfigHandler
45
+ */
46
+ /**
47
+ * @typedef {(value: any, options: object) => any} CallConfigHandler
48
+ */
49
+ /**
50
+ * @typedef {any[]} AppendConfigValues
51
+ */
52
+
27
53
  class OptionsDefaulter {
28
54
  constructor() {
55
+ /**
56
+ * Stores default options settings or functions for computing them
57
+ */
29
58
  this.defaults = {};
59
+ /**
60
+ * Stores configuration for options
61
+ * @type {{[key: string]: ConfigType}}
62
+ */
30
63
  this.config = {};
31
64
  }
32
65
 
66
+ /**
67
+ * Enhancing {@param options} with default values
68
+ * @param {object} options - provided options
69
+ * @returns {object} - enhanced options
70
+ * @throws {Error} - will throw error, if configuration value is other then `undefined` or {@link ConfigType}
71
+ */
33
72
  process(options) {
34
73
  options = Object.assign({}, options);
35
74
  for (let name in this.defaults) {
36
75
  switch (this.config[name]) {
76
+ /**
77
+ * If {@link ConfigType} doesn't specified and current value is `undefined`, then default value will be assigned
78
+ */
37
79
  case undefined:
38
80
  if (getProperty(options, name) === undefined) {
39
81
  setProperty(options, name, this.defaults[name]);
40
82
  }
41
83
  break;
84
+ /**
85
+ * Assign result of {@link CallConfigHandler}
86
+ */
42
87
  case "call":
43
88
  setProperty(
44
89
  options,
@@ -46,11 +91,17 @@ class OptionsDefaulter {
46
91
  this.defaults[name].call(this, getProperty(options, name), options)
47
92
  );
48
93
  break;
94
+ /**
95
+ * Assign result of {@link MakeConfigHandler}, if current value is `undefined`
96
+ */
49
97
  case "make":
50
98
  if (getProperty(options, name) === undefined) {
51
99
  setProperty(options, name, this.defaults[name].call(this, options));
52
100
  }
53
101
  break;
102
+ /**
103
+ * Adding {@link AppendConfigValues} at the end of the current array
104
+ */
54
105
  case "append": {
55
106
  let oldValue = getProperty(options, name);
56
107
  if (!Array.isArray(oldValue)) {
@@ -69,6 +120,13 @@ class OptionsDefaulter {
69
120
  return options;
70
121
  }
71
122
 
123
+ /**
124
+ * Builds up default values
125
+ * @param {string} name - option path
126
+ * @param {ConfigType | any} config - if {@param def} is provided, then only {@link ConfigType} is allowed
127
+ * @param {MakeConfigHandler | CallConfigHandler | AppendConfigValues} [def] - defaults
128
+ * @returns {void}
129
+ */
72
130
  set(name, config, def) {
73
131
  if (def !== undefined) {
74
132
  this.defaults[name] = def;