webpack 2.2.0 → 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.
- package/README.md +39 -63
- package/lib/APIPlugin.js +2 -8
- package/lib/AsyncDependenciesBlock.js +46 -55
- package/lib/ChunkTemplate.js +25 -26
- package/lib/CompatibilityPlugin.js +49 -46
- package/lib/Compilation.js +279 -138
- package/lib/ConstPlugin.js +2 -6
- package/lib/DefinePlugin.js +9 -27
- package/lib/EnvironmentPlugin.js +25 -9
- package/lib/EvalDevToolModulePlugin.js +15 -10
- package/lib/EvalSourceMapDevToolPlugin.js +24 -18
- package/lib/ExtendedAPIPlugin.js +1 -6
- package/lib/FlagDependencyExportsPlugin.js +72 -79
- package/lib/FlagInitialModulesAsUsedPlugin.js +17 -13
- package/lib/FunctionModulePlugin.js +17 -11
- package/lib/HotModuleReplacementPlugin.js +3 -13
- package/lib/HotUpdateChunkTemplate.js +21 -22
- package/lib/JsonpTemplatePlugin.js +15 -11
- package/lib/LoaderTargetPlugin.js +14 -10
- package/lib/MainTemplate.js +193 -191
- package/lib/MultiWatching.js +16 -14
- package/lib/NoEmitOnErrorsPlugin.js +14 -11
- package/lib/NodeStuffPlugin.js +6 -30
- package/lib/NormalModuleFactory.js +2 -2
- package/lib/NormalModuleReplacementPlugin.js +36 -31
- package/lib/Parser.js +8 -7
- package/lib/ParserHelpers.js +19 -5
- package/lib/ProvidePlugin.js +2 -6
- package/lib/RequestShortener.js +49 -47
- package/lib/RequireJsStuffPlugin.js +5 -20
- package/lib/RuleSet.js +28 -20
- package/lib/Template.js +133 -132
- package/lib/compareLocations.js +9 -8
- package/lib/dependencies/AMDPlugin.js +111 -115
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +157 -154
- package/lib/dependencies/CommonJsPlugin.js +81 -85
- package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +73 -75
- package/lib/dependencies/ContextDependencyTemplateAsId.js +21 -18
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +23 -29
- package/lib/dependencies/CriticalDependencyWarning.js +13 -8
- package/lib/dependencies/{HarmonyCompatiblilityDependency.js → HarmonyCompatibilityDependency.js} +3 -3
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +2 -2
- package/lib/dependencies/HarmonyModulesPlugin.js +51 -49
- package/lib/dependencies/ImportParserPlugin.js +31 -28
- package/lib/dependencies/ImportPlugin.js +28 -24
- package/lib/dependencies/LocalModule.js +17 -13
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +15 -17
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +15 -17
- package/lib/dependencies/RequireContextPlugin.js +59 -57
- package/lib/dependencies/RequireEnsurePlugin.js +22 -26
- package/lib/dependencies/RequireIncludePlugin.js +18 -23
- package/lib/dependencies/RequireResolveDependencyParserPlugin.js +59 -56
- package/lib/dependencies/SystemPlugin.js +34 -36
- package/lib/dependencies/WebpackMissingModule.js +10 -18
- package/lib/node/NodeTargetPlugin.js +8 -5
- package/lib/node/NodeWatchFileSystem.js +54 -53
- package/lib/optimize/CommonsChunkPlugin.js +163 -166
- package/lib/optimize/RemoveParentModulesPlugin.js +36 -27
- package/lib/validateSchema.js +18 -18
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +22 -20
- package/package.json +12 -6
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
|
-
|
6
|
-
var ConcatSource = require("webpack-sources").ConcatSource;
|
5
|
+
"use strict";
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
this.outputOptions = outputOptions || {};
|
11
|
-
}
|
12
|
-
module.exports = Template;
|
7
|
+
const Tapable = require("tapable");
|
8
|
+
const ConcatSource = require("webpack-sources").ConcatSource;
|
13
9
|
|
14
|
-
|
15
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
};
|
14
|
+
module.exports = class Template extends Tapable {
|
15
|
+
constructor(outputOptions) {
|
16
|
+
super();
|
17
|
+
this.outputOptions = outputOptions || {};
|
18
|
+
}
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
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
|
-
//
|
36
|
-
n
|
37
|
-
|
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
|
-
|
41
|
-
|
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
|
-
|
44
|
-
|
45
|
-
return
|
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
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
123
|
-
|
124
|
-
var
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
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
|
+
}
|
package/lib/compareLocations.js
CHANGED
@@ -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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
69
|
-
return
|
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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
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;
|