webpack 2.2.0-rc.6 → 2.2.1

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.
Files changed (68) hide show
  1. package/README.md +39 -63
  2. package/bin/webpack.js +3 -3
  3. package/buildin/harmony-module.js +0 -6
  4. package/buildin/module.js +0 -2
  5. package/lib/APIPlugin.js +2 -8
  6. package/lib/AsyncDependenciesBlock.js +46 -55
  7. package/lib/ChunkTemplate.js +25 -26
  8. package/lib/CompatibilityPlugin.js +49 -46
  9. package/lib/Compilation.js +279 -138
  10. package/lib/Compiler.js +5 -2
  11. package/lib/ConstPlugin.js +2 -6
  12. package/lib/DefinePlugin.js +9 -27
  13. package/lib/EnvironmentPlugin.js +25 -9
  14. package/lib/EvalDevToolModulePlugin.js +15 -10
  15. package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +1 -1
  16. package/lib/EvalSourceMapDevToolPlugin.js +24 -18
  17. package/lib/ExtendedAPIPlugin.js +1 -6
  18. package/lib/FlagDependencyExportsPlugin.js +72 -79
  19. package/lib/FlagInitialModulesAsUsedPlugin.js +17 -13
  20. package/lib/FunctionModulePlugin.js +17 -11
  21. package/lib/HotModuleReplacementPlugin.js +3 -13
  22. package/lib/HotUpdateChunkTemplate.js +21 -22
  23. package/lib/JsonpTemplatePlugin.js +15 -11
  24. package/lib/LibManifestPlugin.js +1 -1
  25. package/lib/LoaderTargetPlugin.js +14 -10
  26. package/lib/MainTemplate.js +193 -191
  27. package/lib/MultiWatching.js +16 -14
  28. package/lib/NoEmitOnErrorsPlugin.js +14 -11
  29. package/lib/NodeStuffPlugin.js +6 -30
  30. package/lib/NormalModuleFactory.js +2 -2
  31. package/lib/NormalModuleReplacementPlugin.js +36 -31
  32. package/lib/Parser.js +11 -8
  33. package/lib/ParserHelpers.js +19 -5
  34. package/lib/ProvidePlugin.js +2 -6
  35. package/lib/RequestShortener.js +49 -47
  36. package/lib/RequireJsStuffPlugin.js +5 -20
  37. package/lib/RuleSet.js +28 -20
  38. package/lib/SourceMapDevToolPlugin.js +1 -1
  39. package/lib/Template.js +133 -132
  40. package/lib/compareLocations.js +9 -8
  41. package/lib/dependencies/AMDPlugin.js +111 -115
  42. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +157 -154
  43. package/lib/dependencies/CommonJsPlugin.js +81 -85
  44. package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +73 -75
  45. package/lib/dependencies/ContextDependencyTemplateAsId.js +21 -18
  46. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +23 -29
  47. package/lib/dependencies/CriticalDependencyWarning.js +13 -8
  48. package/lib/dependencies/{HarmonyCompatiblilityDependency.js → HarmonyCompatibilityDependency.js} +3 -3
  49. package/lib/dependencies/HarmonyDetectionParserPlugin.js +2 -2
  50. package/lib/dependencies/HarmonyModulesPlugin.js +51 -49
  51. package/lib/dependencies/ImportParserPlugin.js +31 -28
  52. package/lib/dependencies/ImportPlugin.js +28 -24
  53. package/lib/dependencies/LocalModule.js +17 -13
  54. package/lib/dependencies/ModuleDependencyTemplateAsId.js +15 -17
  55. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +15 -17
  56. package/lib/dependencies/RequireContextPlugin.js +59 -57
  57. package/lib/dependencies/RequireEnsurePlugin.js +22 -26
  58. package/lib/dependencies/RequireIncludePlugin.js +18 -23
  59. package/lib/dependencies/RequireResolveDependencyParserPlugin.js +59 -56
  60. package/lib/dependencies/SystemPlugin.js +34 -36
  61. package/lib/dependencies/WebpackMissingModule.js +10 -18
  62. package/lib/node/NodeTargetPlugin.js +8 -5
  63. package/lib/node/NodeWatchFileSystem.js +54 -53
  64. package/lib/optimize/CommonsChunkPlugin.js +163 -166
  65. package/lib/optimize/RemoveParentModulesPlugin.js +36 -27
  66. package/lib/validateSchema.js +18 -18
  67. package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +22 -20
  68. package/package.json +13 -7
package/lib/Template.js CHANGED
@@ -2,159 +2,160 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- var Tapable = require("tapable");
6
- var ConcatSource = require("webpack-sources").ConcatSource;
5
+ "use strict";
7
6
 
8
- function Template(outputOptions) {
9
- Tapable.call(this);
10
- this.outputOptions = outputOptions || {};
11
- }
12
- module.exports = Template;
7
+ const Tapable = require("tapable");
8
+ const ConcatSource = require("webpack-sources").ConcatSource;
13
9
 
14
- Template.getFunctionContent = function(fn) {
15
- return fn.toString().replace(/^function\s?\(\)\s?\{\n?|\n?\}$/g, "").replace(/^\t/mg, "");
16
- };
10
+ const START_LOWERCASE_ALPHABET_CODE = "a".charCodeAt(0);
11
+ const START_UPPERCASE_ALPHABET_CODE = "A".charCodeAt(0);
12
+ const DELTA_A_TO_Z = "z".charCodeAt(0) - START_LOWERCASE_ALPHABET_CODE + 1;
17
13
 
18
- Template.toIdentifier = function(str) {
19
- if(typeof str !== "string") return "";
20
- return str.replace(/^[^a-zA-Z$_]/, "_").replace(/[^a-zA-Z0-9$_]/g, "_");
21
- };
14
+ module.exports = class Template extends Tapable {
15
+ constructor(outputOptions) {
16
+ super();
17
+ this.outputOptions = outputOptions || {};
18
+ }
22
19
 
23
- var START_LOWERCASE_ALPHABET_CODE = "a".charCodeAt(0);
24
- var START_UPPERCASE_ALPHABET_CODE = "A".charCodeAt(0);
25
- var DELTA_A_TO_Z = "z".charCodeAt(0) - START_LOWERCASE_ALPHABET_CODE + 1;
26
- // map number to a single character a-z, A-Z or <_ + number> if number is too big
27
- Template.numberToIdentifer = function numberToIdentifer(n) {
28
- // lower case
29
- if(n < DELTA_A_TO_Z) return String.fromCharCode(START_LOWERCASE_ALPHABET_CODE + n);
20
+ static getFunctionContent(fn) {
21
+ return fn.toString().replace(/^function\s?\(\)\s?\{\n?|\n?\}$/g, "").replace(/^\t/mg, "");
22
+ }
30
23
 
31
- // upper case
32
- n -= DELTA_A_TO_Z;
33
- if(n < DELTA_A_TO_Z) return String.fromCharCode(START_UPPERCASE_ALPHABET_CODE + n);
24
+ static toIdentifier(str) {
25
+ if(typeof str !== "string") return "";
26
+ return str.replace(/^[^a-zA-Z$_]/, "_").replace(/[^a-zA-Z0-9$_]/g, "_");
27
+ }
34
28
 
35
- // fall back to _ + number
36
- n -= DELTA_A_TO_Z;
37
- return "_" + n;
38
- };
29
+ // map number to a single character a-z, A-Z or <_ + number> if number is too big
30
+ static numberToIdentifer(n) {
31
+ // lower case
32
+ if(n < DELTA_A_TO_Z) return String.fromCharCode(START_LOWERCASE_ALPHABET_CODE + n);
39
33
 
40
- Template.prototype = Object.create(Tapable.prototype);
41
- Template.prototype.constructor = Template;
34
+ // upper case
35
+ n -= DELTA_A_TO_Z;
36
+ if(n < DELTA_A_TO_Z) return String.fromCharCode(START_UPPERCASE_ALPHABET_CODE + n);
42
37
 
43
- Template.prototype.indent = function indent(str) {
44
- if(Array.isArray(str)) {
45
- return str.map(indent).join("\n");
46
- } else {
47
- str = str.trimRight();
48
- if(!str) return "";
49
- var ind = (str[0] === "\n" ? "" : "\t");
50
- return ind + str.replace(/\n([^\n])/g, "\n\t$1");
38
+ // fall back to _ + number
39
+ n -= DELTA_A_TO_Z;
40
+ return "_" + n;
51
41
  }
52
- };
53
42
 
54
- Template.prototype.prefix = function(str, prefix) {
55
- if(Array.isArray(str)) {
56
- str = str.join("\n");
43
+ indent(str) {
44
+ if(Array.isArray(str)) {
45
+ return str.map(this.indent.bind(this)).join("\n");
46
+ } else {
47
+ str = str.trimRight();
48
+ if(!str) return "";
49
+ var ind = (str[0] === "\n" ? "" : "\t");
50
+ return ind + str.replace(/\n([^\n])/g, "\n\t$1");
51
+ }
57
52
  }
58
- str = str.trim();
59
- if(!str) return "";
60
- var ind = (str[0] === "\n" ? "" : prefix);
61
- return ind + str.replace(/\n([^\n])/g, "\n" + prefix + "$1");
62
- };
63
53
 
64
- Template.prototype.asString = function(str) {
65
- if(Array.isArray(str)) {
66
- return str.join("\n");
54
+ prefix(str, prefix) {
55
+ if(Array.isArray(str)) {
56
+ str = str.join("\n");
57
+ }
58
+ str = str.trim();
59
+ if(!str) return "";
60
+ let ind = (str[0] === "\n" ? "" : prefix);
61
+ return ind + str.replace(/\n([^\n])/g, "\n" + prefix + "$1");
67
62
  }
68
- return str;
69
- };
70
63
 
71
- function moduleIdIsNumber(module) {
72
- return typeof module.id === "number";
73
- }
74
-
75
- Template.prototype.getModulesArrayBounds = function(modules) {
76
- if(!modules.every(moduleIdIsNumber))
77
- return false;
78
- var maxId = -Infinity;
79
- var minId = Infinity;
80
- modules.forEach(function(module) {
81
- if(maxId < module.id) maxId = module.id;
82
- if(minId > module.id) minId = module.id;
83
- });
84
- if(minId < 16 + ("" + minId).length) {
85
- // add minId x ',' instead of 'Array(minId).concat(...)'
86
- minId = 0;
64
+ asString(str) {
65
+ if(Array.isArray(str)) {
66
+ return str.join("\n");
67
+ }
68
+ return str;
87
69
  }
88
- var objectOverhead = modules.map(function(module) {
89
- var idLength = (module.id + "").length;
90
- return idLength + 2;
91
- }).reduce(function(a, b) {
92
- return a + b;
93
- }, -1);
94
- var arrayOverhead = minId === 0 ? maxId : 16 + ("" + minId).length + maxId;
95
- return arrayOverhead < objectOverhead ? [minId, maxId] : false;
96
- };
97
70
 
98
- Template.prototype.renderChunkModules = function(chunk, moduleTemplate, dependencyTemplates, prefix) {
99
- if(!prefix) prefix = "";
100
- var source = new ConcatSource();
101
- if(chunk.modules.length === 0) {
102
- source.add("[]");
103
- return source;
104
- }
105
- var removedModules = chunk.removedModules;
106
- var allModules = chunk.modules.map(function(module) {
107
- return {
108
- id: module.id,
109
- source: moduleTemplate.render(module, dependencyTemplates, chunk)
110
- };
111
- });
112
- if(removedModules && removedModules.length > 0) {
113
- removedModules.forEach(function(id) {
114
- allModules.push({
115
- id: id,
116
- source: "false"
117
- });
71
+ getModulesArrayBounds(modules) {
72
+ if(!modules.every(moduleIdIsNumber))
73
+ return false;
74
+ var maxId = -Infinity;
75
+ var minId = Infinity;
76
+ modules.forEach(function(module) {
77
+ if(maxId < module.id) maxId = module.id;
78
+ if(minId > module.id) minId = module.id;
118
79
  });
80
+ if(minId < 16 + ("" + minId).length) {
81
+ // add minId x ',' instead of 'Array(minId).concat(...)'
82
+ minId = 0;
83
+ }
84
+ var objectOverhead = modules.map(function(module) {
85
+ var idLength = (module.id + "").length;
86
+ return idLength + 2;
87
+ }).reduce(function(a, b) {
88
+ return a + b;
89
+ }, -1);
90
+ var arrayOverhead = minId === 0 ? maxId : 16 + ("" + minId).length + maxId;
91
+ return arrayOverhead < objectOverhead ? [minId, maxId] : false;
119
92
  }
120
- var bounds = this.getModulesArrayBounds(chunk.modules);
121
93
 
122
- if(bounds) {
123
- // Render a spare array
124
- var minId = bounds[0];
125
- var maxId = bounds[1];
126
- if(minId !== 0) source.add("Array(" + minId + ").concat(");
127
- source.add("[\n");
128
- var modules = {};
129
- allModules.forEach(function(module) {
130
- modules[module.id] = module;
94
+ renderChunkModules(chunk, moduleTemplate, dependencyTemplates, prefix) {
95
+ if(!prefix) prefix = "";
96
+ var source = new ConcatSource();
97
+ if(chunk.modules.length === 0) {
98
+ source.add("[]");
99
+ return source;
100
+ }
101
+ var removedModules = chunk.removedModules;
102
+ var allModules = chunk.modules.map(function(module) {
103
+ return {
104
+ id: module.id,
105
+ source: moduleTemplate.render(module, dependencyTemplates, chunk)
106
+ };
131
107
  });
132
- for(var idx = minId; idx <= maxId; idx++) {
133
- var module = modules[idx];
134
- if(idx !== minId) source.add(",\n");
135
- source.add("/* " + idx + " */");
136
- if(module) {
137
- source.add("\n");
138
- source.add(module.source);
108
+ if(removedModules && removedModules.length > 0) {
109
+ removedModules.forEach(function(id) {
110
+ allModules.push({
111
+ id: id,
112
+ source: "false"
113
+ });
114
+ });
115
+ }
116
+ var bounds = this.getModulesArrayBounds(chunk.modules);
117
+
118
+ if(bounds) {
119
+ // Render a spare array
120
+ var minId = bounds[0];
121
+ var maxId = bounds[1];
122
+ if(minId !== 0) source.add("Array(" + minId + ").concat(");
123
+ source.add("[\n");
124
+ var modules = {};
125
+ allModules.forEach(function(module) {
126
+ modules[module.id] = module;
127
+ });
128
+ for(var idx = minId; idx <= maxId; idx++) {
129
+ var module = modules[idx];
130
+ if(idx !== minId) source.add(",\n");
131
+ source.add("/* " + idx + " */");
132
+ if(module) {
133
+ source.add("\n");
134
+ source.add(module.source);
135
+ }
139
136
  }
137
+ source.add("\n" + prefix + "]");
138
+ if(minId !== 0) source.add(")");
139
+ } else {
140
+ // Render an object
141
+ source.add("{\n");
142
+ allModules.sort(function(a, b) {
143
+ var aId = a.id + "";
144
+ var bId = b.id + "";
145
+ if(aId < bId) return -1;
146
+ if(aId > bId) return 1;
147
+ return 0;
148
+ }).forEach(function(module, idx) {
149
+ if(idx !== 0) source.add(",\n");
150
+ source.add("\n/***/ " + JSON.stringify(module.id) + ":\n");
151
+ source.add(module.source);
152
+ });
153
+ source.add("\n\n" + prefix + "}");
140
154
  }
141
- source.add("\n" + prefix + "]");
142
- if(minId !== 0) source.add(")");
143
- } else {
144
- // Render an object
145
- source.add("{\n");
146
- allModules.sort(function(a, b) {
147
- var aId = a.id + "";
148
- var bId = b.id + "";
149
- if(aId < bId) return -1;
150
- if(aId > bId) return 1;
151
- return 0;
152
- }).forEach(function(module, idx) {
153
- if(idx !== 0) source.add(",\n");
154
- source.add("\n/***/ " + JSON.stringify(module.id) + ":\n");
155
- source.add(module.source);
156
- });
157
- source.add("\n\n" + prefix + "}");
155
+ return source;
158
156
  }
159
- return source;
160
157
  };
158
+
159
+ function moduleIdIsNumber(module) {
160
+ return typeof module.id === "number";
161
+ }
@@ -2,6 +2,7 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
+ "use strict";
5
6
  module.exports = function compareLocations(a, b) {
6
7
  if(typeof a === "string") {
7
8
  if(typeof b === "string") {
@@ -17,14 +18,14 @@ module.exports = function compareLocations(a, b) {
17
18
  if(typeof b === "string") {
18
19
  return -1;
19
20
  } else if(typeof b === "object") {
20
- var aa = a.start ? a.start : a;
21
- var bb = b.start ? b.start : b;
22
- if(aa.line < bb.line) return -1;
23
- if(aa.line > bb.line) return 1;
24
- if(aa.column < bb.column) return -1;
25
- if(aa.column > bb.column) return 1;
26
- if(aa.index < bb.index) return -1;
27
- if(aa.index > bb.index) return 1;
21
+ if(a.start && b.start) {
22
+ const ap = a.start;
23
+ const bp = b.start;
24
+ if(ap.line < bp.line) return -1;
25
+ if(ap.line > bp.line) return 1;
26
+ if(ap.column < bp.column) return -1;
27
+ if(ap.column > bp.column) return 1;
28
+ }
28
29
  if(a.index < b.index) return -1;
29
30
  if(a.index > b.index) return 1;
30
31
  return 0;
@@ -2,122 +2,118 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- var path = require("path");
6
- var AMDRequireDependency = require("./AMDRequireDependency");
7
- var AMDRequireItemDependency = require("./AMDRequireItemDependency");
8
- var AMDRequireArrayDependency = require("./AMDRequireArrayDependency");
9
- var AMDRequireContextDependency = require("./AMDRequireContextDependency");
10
- var AMDDefineDependency = require("./AMDDefineDependency");
11
- var UnsupportedDependency = require("./UnsupportedDependency");
12
- var LocalModuleDependency = require("./LocalModuleDependency");
13
-
14
- var NullFactory = require("../NullFactory");
15
-
16
- var AMDRequireDependenciesBlockParserPlugin = require("./AMDRequireDependenciesBlockParserPlugin");
17
- var AMDDefineDependencyParserPlugin = require("./AMDDefineDependencyParserPlugin");
18
-
19
- var AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");
20
-
21
- var BasicEvaluatedExpression = require("../BasicEvaluatedExpression");
22
- var ParserHelpers = require("../ParserHelpers");
23
-
24
- function AMDPlugin(options, amdOptions) {
25
- this.amdOptions = amdOptions;
26
- this.options = options;
27
- }
28
- module.exports = AMDPlugin;
29
-
30
- AMDPlugin.prototype.apply = function(compiler) {
31
- var options = this.options;
32
- var amdOptions = this.amdOptions;
33
- compiler.plugin("compilation", function(compilation, params) {
34
- var normalModuleFactory = params.normalModuleFactory;
35
- var contextModuleFactory = params.contextModuleFactory;
36
-
37
- compilation.dependencyFactories.set(AMDRequireDependency, new NullFactory());
38
- compilation.dependencyTemplates.set(AMDRequireDependency, new AMDRequireDependency.Template());
39
-
40
- compilation.dependencyFactories.set(AMDRequireItemDependency, normalModuleFactory);
41
- compilation.dependencyTemplates.set(AMDRequireItemDependency, new AMDRequireItemDependency.Template());
42
-
43
- compilation.dependencyFactories.set(AMDRequireArrayDependency, new NullFactory());
44
- compilation.dependencyTemplates.set(AMDRequireArrayDependency, new AMDRequireArrayDependency.Template());
45
-
46
- compilation.dependencyFactories.set(AMDRequireContextDependency, contextModuleFactory);
47
- compilation.dependencyTemplates.set(AMDRequireContextDependency, new AMDRequireContextDependency.Template());
48
-
49
- compilation.dependencyFactories.set(AMDDefineDependency, new NullFactory());
50
- compilation.dependencyTemplates.set(AMDDefineDependency, new AMDDefineDependency.Template());
51
-
52
- compilation.dependencyFactories.set(UnsupportedDependency, new NullFactory());
53
- compilation.dependencyTemplates.set(UnsupportedDependency, new UnsupportedDependency.Template());
54
-
55
- compilation.dependencyFactories.set(LocalModuleDependency, new NullFactory());
56
- compilation.dependencyTemplates.set(LocalModuleDependency, new LocalModuleDependency.Template());
57
-
58
- params.normalModuleFactory.plugin("parser", function(parser, parserOptions) {
59
-
60
- if(typeof parserOptions.amd !== "undefined" && !parserOptions.amd)
61
- return;
62
-
63
- function setExpressionToModule(expr, module) {
64
- parser.plugin("expression " + expr, function(expr) {
65
- var dep = new AMDRequireItemDependency(module, expr.range);
66
- dep.userRequest = expr;
5
+ "use strict";
6
+
7
+ const path = require("path");
8
+ const AMDRequireDependency = require("./AMDRequireDependency");
9
+ const AMDRequireItemDependency = require("./AMDRequireItemDependency");
10
+ const AMDRequireArrayDependency = require("./AMDRequireArrayDependency");
11
+ const AMDRequireContextDependency = require("./AMDRequireContextDependency");
12
+ const AMDDefineDependency = require("./AMDDefineDependency");
13
+ const UnsupportedDependency = require("./UnsupportedDependency");
14
+ const LocalModuleDependency = require("./LocalModuleDependency");
15
+
16
+ const NullFactory = require("../NullFactory");
17
+
18
+ const AMDRequireDependenciesBlockParserPlugin = require("./AMDRequireDependenciesBlockParserPlugin");
19
+ const AMDDefineDependencyParserPlugin = require("./AMDDefineDependencyParserPlugin");
20
+
21
+ const AliasPlugin = require("enhanced-resolve/lib/AliasPlugin");
22
+
23
+ const ParserHelpers = require("../ParserHelpers");
24
+
25
+ class AMDPlugin {
26
+ constructor(options, amdOptions) {
27
+ this.amdOptions = amdOptions;
28
+ this.options = options;
29
+ }
30
+
31
+ apply(compiler) {
32
+ const options = this.options;
33
+ const amdOptions = this.amdOptions;
34
+ compiler.plugin("compilation", (compilation, params) => {
35
+ const normalModuleFactory = params.normalModuleFactory;
36
+ const contextModuleFactory = params.contextModuleFactory;
37
+
38
+ compilation.dependencyFactories.set(AMDRequireDependency, new NullFactory());
39
+ compilation.dependencyTemplates.set(AMDRequireDependency, new AMDRequireDependency.Template());
40
+
41
+ compilation.dependencyFactories.set(AMDRequireItemDependency, normalModuleFactory);
42
+ compilation.dependencyTemplates.set(AMDRequireItemDependency, new AMDRequireItemDependency.Template());
43
+
44
+ compilation.dependencyFactories.set(AMDRequireArrayDependency, new NullFactory());
45
+ compilation.dependencyTemplates.set(AMDRequireArrayDependency, new AMDRequireArrayDependency.Template());
46
+
47
+ compilation.dependencyFactories.set(AMDRequireContextDependency, contextModuleFactory);
48
+ compilation.dependencyTemplates.set(AMDRequireContextDependency, new AMDRequireContextDependency.Template());
49
+
50
+ compilation.dependencyFactories.set(AMDDefineDependency, new NullFactory());
51
+ compilation.dependencyTemplates.set(AMDDefineDependency, new AMDDefineDependency.Template());
52
+
53
+ compilation.dependencyFactories.set(UnsupportedDependency, new NullFactory());
54
+ compilation.dependencyTemplates.set(UnsupportedDependency, new UnsupportedDependency.Template());
55
+
56
+ compilation.dependencyFactories.set(LocalModuleDependency, new NullFactory());
57
+ compilation.dependencyTemplates.set(LocalModuleDependency, new LocalModuleDependency.Template());
58
+
59
+ params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
60
+
61
+ if(typeof parserOptions.amd !== "undefined" && !parserOptions.amd)
62
+ return;
63
+
64
+ function setExpressionToModule(expr, module) {
65
+ parser.plugin("expression " + expr, (expr) => {
66
+ const dep = new AMDRequireItemDependency(module, expr.range);
67
+ dep.userRequest = expr;
68
+ dep.loc = expr.loc;
69
+ parser.state.current.addDependency(dep);
70
+ return true;
71
+ });
72
+ }
73
+
74
+ parser.apply(
75
+ new AMDRequireDependenciesBlockParserPlugin(options),
76
+ new AMDDefineDependencyParserPlugin(options)
77
+ );
78
+ setExpressionToModule("require.amd", "!!webpack amd options");
79
+ setExpressionToModule("define.amd", "!!webpack amd options");
80
+ setExpressionToModule("define", "!!webpack amd define");
81
+ parser.plugin("expression __webpack_amd_options__", () =>
82
+ parser.state.current.addVariable("__webpack_amd_options__", JSON.stringify(amdOptions)));
83
+ parser.plugin("evaluate typeof define.amd", ParserHelpers.evaluateToString(typeof amdOptions));
84
+ parser.plugin("evaluate typeof require.amd", ParserHelpers.evaluateToString(typeof amdOptions));
85
+ parser.plugin("evaluate Identifier define.amd", ParserHelpers.evaluateToBoolean(true));
86
+ parser.plugin("evaluate Identifier require.amd", ParserHelpers.evaluateToBoolean(true));
87
+ parser.plugin("typeof define", ParserHelpers.toConstantDependency(JSON.stringify("function")));
88
+ parser.plugin("evaluate typeof define", ParserHelpers.evaluateToString("function"));
89
+ parser.plugin("can-rename define", ParserHelpers.approve);
90
+ parser.plugin("rename define", (expr) => {
91
+ const dep = new AMDRequireItemDependency("!!webpack amd define", expr.range);
92
+ dep.userRequest = "define";
67
93
  dep.loc = expr.loc;
68
- this.state.current.addDependency(dep);
69
- return true;
94
+ parser.state.current.addDependency(dep);
95
+ return false;
70
96
  });
71
- }
72
-
73
- parser.apply(
74
- new AMDRequireDependenciesBlockParserPlugin(options),
75
- new AMDDefineDependencyParserPlugin(options)
76
- );
77
- setExpressionToModule("require.amd", "!!webpack amd options");
78
- setExpressionToModule("define.amd", "!!webpack amd options");
79
- setExpressionToModule("define", "!!webpack amd define");
80
- parser.plugin("expression __webpack_amd_options__", function() {
81
- return this.state.current.addVariable("__webpack_amd_options__", JSON.stringify(amdOptions));
82
- });
83
- parser.plugin("evaluate typeof define.amd", ParserHelpers.evaluateToString(typeof amdOptions));
84
- parser.plugin("evaluate typeof require.amd", ParserHelpers.evaluateToString(typeof amdOptions));
85
- parser.plugin("evaluate Identifier define.amd", function(expr) {
86
- return new BasicEvaluatedExpression().setBoolean(true).setRange(expr.range);
97
+ parser.plugin("typeof require", ParserHelpers.toConstantDependency(JSON.stringify("function")));
98
+ parser.plugin("evaluate typeof require", ParserHelpers.evaluateToString("function"));
87
99
  });
88
- parser.plugin("evaluate Identifier require.amd", function(expr) {
89
- return new BasicEvaluatedExpression().setBoolean(true).setRange(expr.range);
90
- });
91
- parser.plugin("typeof define", ParserHelpers.toConstantDependency("function"));
92
- parser.plugin("evaluate typeof define", ParserHelpers.evaluateToString("function"));
93
- parser.plugin("can-rename define", function() {
94
- return true;
95
- });
96
- parser.plugin("rename define", function(expr) {
97
- var dep = new AMDRequireItemDependency("!!webpack amd define", expr.range);
98
- dep.userRequest = "define";
99
- dep.loc = expr.loc;
100
- this.state.current.addDependency(dep);
101
- return false;
102
- });
103
- parser.plugin("typeof require", ParserHelpers.toConstantDependency("function"));
104
- parser.plugin("evaluate typeof require", ParserHelpers.evaluateToString("function"));
105
100
  });
106
- });
107
- compiler.plugin("after-resolvers", function() {
108
- compiler.resolvers.normal.apply(
109
- new AliasPlugin("described-resolve", {
110
- name: "amdefine",
111
- alias: path.join(__dirname, "..", "..", "buildin", "amd-define.js")
112
- }, "resolve"),
113
- new AliasPlugin("described-resolve", {
114
- name: "webpack amd options",
115
- alias: path.join(__dirname, "..", "..", "buildin", "amd-options.js")
116
- }, "resolve"),
117
- new AliasPlugin("described-resolve", {
118
- name: "webpack amd define",
119
- alias: path.join(__dirname, "..", "..", "buildin", "amd-define.js")
120
- }, "resolve")
121
- );
122
- });
123
- };
101
+ compiler.plugin("after-resolvers", () => {
102
+ compiler.resolvers.normal.apply(
103
+ new AliasPlugin("described-resolve", {
104
+ name: "amdefine",
105
+ alias: path.join(__dirname, "..", "..", "buildin", "amd-define.js")
106
+ }, "resolve"),
107
+ new AliasPlugin("described-resolve", {
108
+ name: "webpack amd options",
109
+ alias: path.join(__dirname, "..", "..", "buildin", "amd-options.js")
110
+ }, "resolve"),
111
+ new AliasPlugin("described-resolve", {
112
+ name: "webpack amd define",
113
+ alias: path.join(__dirname, "..", "..", "buildin", "amd-define.js")
114
+ }, "resolve")
115
+ );
116
+ });
117
+ }
118
+ }
119
+ module.exports = AMDPlugin;