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
@@ -2,22 +2,20 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
6
|
-
module.exports = ModuleDependencyTemplateAsId;
|
5
|
+
"use strict";
|
7
6
|
|
8
|
-
ModuleDependencyTemplateAsId
|
9
|
-
if(!dep.range) return;
|
10
|
-
var comment = "";
|
11
|
-
if(outputOptions.pathinfo) comment = "/*! " + requestShortener.shorten(dep.request) + " */ ";
|
12
|
-
var content;
|
13
|
-
if(dep.module)
|
14
|
-
content = comment + JSON.stringify(dep.module.id);
|
15
|
-
else
|
16
|
-
content = require("./WebpackMissingModule").module(dep.request);
|
17
|
-
source.replace(dep.range[0], dep.range[1] - 1, content);
|
18
|
-
};
|
7
|
+
class ModuleDependencyTemplateAsId {
|
19
8
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
}
|
9
|
+
apply(dep, source, outputOptions, requestShortener) {
|
10
|
+
if(!dep.range) return;
|
11
|
+
let comment = "";
|
12
|
+
if(outputOptions.pathinfo) comment = `/*! ${requestShortener.shorten(dep.request)} */ `;
|
13
|
+
let content;
|
14
|
+
if(dep.module)
|
15
|
+
content = comment + JSON.stringify(dep.module.id);
|
16
|
+
else
|
17
|
+
content = require("./WebpackMissingModule").module(dep.request);
|
18
|
+
source.replace(dep.range[0], dep.range[1] - 1, content);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
module.exports = ModuleDependencyTemplateAsId;
|
@@ -2,22 +2,20 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
6
|
-
module.exports = ModuleDependencyTemplateAsRequireId;
|
5
|
+
"use strict";
|
7
6
|
|
8
|
-
ModuleDependencyTemplateAsRequireId
|
9
|
-
if(!dep.range) return;
|
10
|
-
var comment = "";
|
11
|
-
if(outputOptions.pathinfo) comment = "/*! " + requestShortener.shorten(dep.request) + " */ ";
|
12
|
-
var content;
|
13
|
-
if(dep.module)
|
14
|
-
content = "__webpack_require__(" + comment + JSON.stringify(dep.module.id) + ")";
|
15
|
-
else
|
16
|
-
content = require("./WebpackMissingModule").module(dep.request);
|
17
|
-
source.replace(dep.range[0], dep.range[1] - 1, content);
|
18
|
-
};
|
7
|
+
class ModuleDependencyTemplateAsRequireId {
|
19
8
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
}
|
9
|
+
apply(dep, source, outputOptions, requestShortener) {
|
10
|
+
if(!dep.range) return;
|
11
|
+
let comment = "";
|
12
|
+
if(outputOptions.pathinfo) comment = `/*! ${requestShortener.shorten(dep.request)} */ `;
|
13
|
+
let content;
|
14
|
+
if(dep.module)
|
15
|
+
content = `__webpack_require__(${comment}${JSON.stringify(dep.module.id)})`;
|
16
|
+
else
|
17
|
+
content = require("./WebpackMissingModule").module(dep.request);
|
18
|
+
source.replace(dep.range[0], dep.range[1] - 1, content);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
module.exports = ModuleDependencyTemplateAsRequireId;
|
@@ -2,74 +2,76 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
6
|
-
var ContextElementDependency = require("./ContextElementDependency");
|
5
|
+
"use strict";
|
7
6
|
|
8
|
-
|
7
|
+
const RequireContextDependency = require("./RequireContextDependency");
|
8
|
+
const ContextElementDependency = require("./ContextElementDependency");
|
9
9
|
|
10
|
-
|
11
|
-
if(!Array.isArray(modulesDirectories))
|
12
|
-
throw new Error("modulesDirectories must be an array");
|
13
|
-
if(!Array.isArray(extensions))
|
14
|
-
throw new Error("extensions must be an array");
|
15
|
-
this.modulesDirectories = modulesDirectories;
|
16
|
-
this.extensions = extensions;
|
17
|
-
}
|
18
|
-
module.exports = RequireContextPlugin;
|
10
|
+
const RequireContextDependencyParserPlugin = require("./RequireContextDependencyParserPlugin");
|
19
11
|
|
20
|
-
RequireContextPlugin
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
12
|
+
class RequireContextPlugin {
|
13
|
+
constructor(modulesDirectories, extensions) {
|
14
|
+
if(!Array.isArray(modulesDirectories))
|
15
|
+
throw new Error("modulesDirectories must be an array");
|
16
|
+
if(!Array.isArray(extensions))
|
17
|
+
throw new Error("extensions must be an array");
|
18
|
+
this.modulesDirectories = modulesDirectories;
|
19
|
+
this.extensions = extensions;
|
20
|
+
}
|
26
21
|
|
27
|
-
|
28
|
-
|
22
|
+
apply(compiler) {
|
23
|
+
const modulesDirectories = this.modulesDirectories;
|
24
|
+
const extensions = this.extensions;
|
25
|
+
compiler.plugin("compilation", (compilation, params) => {
|
26
|
+
const contextModuleFactory = params.contextModuleFactory;
|
27
|
+
const normalModuleFactory = params.normalModuleFactory;
|
29
28
|
|
30
|
-
|
29
|
+
compilation.dependencyFactories.set(RequireContextDependency, contextModuleFactory);
|
30
|
+
compilation.dependencyTemplates.set(RequireContextDependency, new RequireContextDependency.Template());
|
31
31
|
|
32
|
-
|
32
|
+
compilation.dependencyFactories.set(ContextElementDependency, normalModuleFactory);
|
33
33
|
|
34
|
-
|
35
|
-
return;
|
34
|
+
params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
|
36
35
|
|
37
|
-
|
38
|
-
|
36
|
+
if(typeof parserOptions.requireContext !== "undefined" && !parserOptions.requireContext)
|
37
|
+
return;
|
39
38
|
|
40
|
-
|
41
|
-
|
39
|
+
parser.apply(new RequireContextDependencyParserPlugin());
|
40
|
+
});
|
42
41
|
|
43
|
-
|
44
|
-
return
|
45
|
-
var l = obj.request.length;
|
46
|
-
return l > ext.length && obj.request.substr(l - ext.length, l) === ext;
|
47
|
-
}).map(function(ext) {
|
48
|
-
var l = obj.request.length;
|
49
|
-
return {
|
50
|
-
context: obj.context,
|
51
|
-
request: obj.request.substr(0, l - ext.length)
|
52
|
-
};
|
53
|
-
}).concat(obj);
|
54
|
-
}).reduce(function(a, b) {
|
55
|
-
return a.concat(b);
|
56
|
-
}, []));
|
57
|
-
});
|
42
|
+
params.contextModuleFactory.plugin("alternatives", (items, callback) => {
|
43
|
+
if(items.length === 0) return callback(null, items);
|
58
44
|
|
59
|
-
|
60
|
-
|
45
|
+
callback(null, items.map((obj) => {
|
46
|
+
return extensions.filter((ext) => {
|
47
|
+
const l = obj.request.length;
|
48
|
+
return l > ext.length && obj.request.substr(l - ext.length, l) === ext;
|
49
|
+
}).map((ext) => {
|
50
|
+
const l = obj.request.length;
|
51
|
+
return {
|
52
|
+
context: obj.context,
|
53
|
+
request: obj.request.substr(0, l - ext.length)
|
54
|
+
};
|
55
|
+
}).concat(obj);
|
56
|
+
}).reduce((a, b) => a.concat(b), []));
|
57
|
+
});
|
61
58
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
59
|
+
params.contextModuleFactory.plugin("alternatives", (items, callback) => {
|
60
|
+
if(items.length === 0) return callback(null, items);
|
61
|
+
|
62
|
+
callback(null, items.map((obj) => {
|
63
|
+
for(let i = 0; i < modulesDirectories.length; i++) {
|
64
|
+
const dir = modulesDirectories[i];
|
65
|
+
const idx = obj.request.indexOf("./" + dir + "/");
|
66
|
+
if(idx === 0) {
|
67
|
+
obj.request = obj.request.slice(dir.length + 3);
|
68
|
+
break;
|
69
|
+
}
|
69
70
|
}
|
70
|
-
|
71
|
-
|
72
|
-
})
|
71
|
+
return obj;
|
72
|
+
}));
|
73
|
+
});
|
73
74
|
});
|
74
|
-
}
|
75
|
-
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
module.exports = RequireContextPlugin;
|
@@ -3,42 +3,38 @@
|
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
|
-
var RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
|
7
|
-
var RequireEnsureDependency = require("./RequireEnsureDependency");
|
8
|
-
var ConstDependency = require("./ConstDependency");
|
9
6
|
|
10
|
-
|
7
|
+
const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
|
8
|
+
const RequireEnsureDependency = require("./RequireEnsureDependency");
|
11
9
|
|
12
|
-
|
10
|
+
const NullFactory = require("../NullFactory");
|
11
|
+
|
12
|
+
const RequireEnsureDependenciesBlockParserPlugin = require("./RequireEnsureDependenciesBlockParserPlugin");
|
13
13
|
|
14
14
|
const ParserHelpers = require("../ParserHelpers");
|
15
15
|
|
16
|
-
|
17
|
-
module.exports = RequireEnsurePlugin;
|
16
|
+
class RequireEnsurePlugin {
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
apply(compiler) {
|
19
|
+
compiler.plugin("compilation", (compilation, params) => {
|
20
|
+
const normalModuleFactory = params.normalModuleFactory;
|
22
21
|
|
23
|
-
|
24
|
-
|
22
|
+
compilation.dependencyFactories.set(RequireEnsureItemDependency, normalModuleFactory);
|
23
|
+
compilation.dependencyTemplates.set(RequireEnsureItemDependency, new RequireEnsureItemDependency.Template());
|
25
24
|
|
26
|
-
|
27
|
-
|
25
|
+
compilation.dependencyFactories.set(RequireEnsureDependency, new NullFactory());
|
26
|
+
compilation.dependencyTemplates.set(RequireEnsureDependency, new RequireEnsureDependency.Template());
|
28
27
|
|
29
|
-
|
28
|
+
params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
|
30
29
|
|
31
|
-
|
32
|
-
|
30
|
+
if(typeof parserOptions.requireEnsure !== "undefined" && !parserOptions.requireEnsure)
|
31
|
+
return;
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
var dep = new ConstDependency("'function'", expr.range);
|
38
|
-
dep.loc = expr.loc;
|
39
|
-
this.state.current.addDependency(dep);
|
40
|
-
return true;
|
33
|
+
parser.apply(new RequireEnsureDependenciesBlockParserPlugin());
|
34
|
+
parser.plugin("evaluate typeof require.ensure", ParserHelpers.evaluateToString("function"));
|
35
|
+
parser.plugin("typeof require.ensure", ParserHelpers.toConstantDependency(JSON.stringify("function")));
|
41
36
|
});
|
42
37
|
});
|
43
|
-
}
|
44
|
-
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
module.exports = RequireEnsurePlugin;
|
@@ -3,36 +3,31 @@
|
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
|
7
|
+
const RequireIncludeDependency = require("./RequireIncludeDependency");
|
8
|
+
const RequireIncludeDependencyParserPlugin = require("./RequireIncludeDependencyParserPlugin");
|
9
9
|
|
10
10
|
const ParserHelpers = require("../ParserHelpers");
|
11
11
|
|
12
|
-
|
13
|
-
module.exports = RequireIncludePlugin;
|
12
|
+
class RequireIncludePlugin {
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
apply(compiler) {
|
15
|
+
compiler.plugin("compilation", (compilation, params) => {
|
16
|
+
const normalModuleFactory = params.normalModuleFactory;
|
18
17
|
|
19
|
-
|
20
|
-
|
18
|
+
compilation.dependencyFactories.set(RequireIncludeDependency, normalModuleFactory);
|
19
|
+
compilation.dependencyTemplates.set(RequireIncludeDependency, new RequireIncludeDependency.Template());
|
21
20
|
|
22
|
-
|
21
|
+
params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
|
23
22
|
|
24
|
-
|
25
|
-
|
23
|
+
if(typeof parserOptions.requireInclude !== "undefined" && !parserOptions.requireInclude)
|
24
|
+
return;
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
var dep = new ConstDependency("'function'", expr.range);
|
31
|
-
dep.loc = expr.loc;
|
32
|
-
this.state.current.addDependency(dep);
|
33
|
-
return true;
|
26
|
+
parser.apply(new RequireIncludeDependencyParserPlugin());
|
27
|
+
parser.plugin("evaluate typeof require.include", ParserHelpers.evaluateToString("function"));
|
28
|
+
parser.plugin("typeof require.include", ParserHelpers.toConstantDependency(JSON.stringify("function")));
|
34
29
|
});
|
35
|
-
|
36
30
|
});
|
37
|
-
}
|
38
|
-
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
module.exports = RequireIncludePlugin;
|
@@ -2,68 +2,71 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
6
|
-
var RequireResolveContextDependency = require("./RequireResolveContextDependency");
|
7
|
-
var RequireResolveHeaderDependency = require("./RequireResolveHeaderDependency");
|
8
|
-
var ContextDependencyHelpers = require("./ContextDependencyHelpers");
|
5
|
+
"use strict";
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
const RequireResolveDependency = require("./RequireResolveDependency");
|
8
|
+
const RequireResolveContextDependency = require("./RequireResolveContextDependency");
|
9
|
+
const RequireResolveHeaderDependency = require("./RequireResolveHeaderDependency");
|
10
|
+
const ContextDependencyHelpers = require("./ContextDependencyHelpers");
|
13
11
|
|
14
|
-
|
12
|
+
class RequireResolveDependencyParserPlugin {
|
13
|
+
constructor(options) {
|
14
|
+
this.options = options;
|
15
|
+
}
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
17
|
+
apply(parser) {
|
18
|
+
const options = this.options;
|
19
|
+
parser.plugin("call require.resolve", (expr) => {
|
20
|
+
return parser.applyPluginsBailResult("call require.resolve(Weak)", expr, false);
|
21
|
+
});
|
22
|
+
parser.plugin("call require.resolveWeak", (expr) => {
|
23
|
+
return parser.applyPluginsBailResult("call require.resolve(Weak)", expr, true);
|
24
|
+
});
|
25
|
+
parser.plugin("call require.resolve(Weak)", (expr, weak) => {
|
26
|
+
if(expr.arguments.length !== 1) return;
|
27
|
+
const param = parser.evaluateExpression(expr.arguments[0]);
|
28
|
+
let dep;
|
29
|
+
if(param.isConditional()) {
|
30
|
+
param.options.forEach((option) => {
|
31
|
+
const result = parser.applyPluginsBailResult("call require.resolve(Weak):item", expr, option, weak);
|
32
|
+
if(result === undefined) {
|
33
|
+
parser.applyPluginsBailResult("call require.resolve(Weak):context", expr, option, weak);
|
34
|
+
}
|
35
|
+
});
|
36
|
+
dep = new RequireResolveHeaderDependency(expr.callee.range);
|
37
|
+
dep.loc = expr.loc;
|
38
|
+
parser.state.current.addDependency(dep);
|
39
|
+
return true;
|
40
|
+
} else {
|
41
|
+
const result = parser.applyPluginsBailResult("call require.resolve(Weak):item", expr, param, weak);
|
31
42
|
if(result === undefined) {
|
32
|
-
|
43
|
+
parser.applyPluginsBailResult("call require.resolve(Weak):context", expr, param, weak);
|
33
44
|
}
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
return true;
|
39
|
-
} else {
|
40
|
-
var result = this.applyPluginsBailResult("call require.resolve(Weak):item", expr, param, weak);
|
41
|
-
if(result === undefined) {
|
42
|
-
this.applyPluginsBailResult("call require.resolve(Weak):context", expr, param, weak);
|
45
|
+
dep = new RequireResolveHeaderDependency(expr.callee.range);
|
46
|
+
dep.loc = expr.loc;
|
47
|
+
parser.state.current.addDependency(dep);
|
48
|
+
return true;
|
43
49
|
}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
});
|
51
|
+
parser.plugin("call require.resolve(Weak):item", (expr, param, weak) => {
|
52
|
+
if(param.isString()) {
|
53
|
+
const dep = new RequireResolveDependency(param.string, param.range);
|
54
|
+
dep.loc = expr.loc;
|
55
|
+
dep.optional = !!parser.scope.inTry;
|
56
|
+
dep.weak = weak;
|
57
|
+
parser.state.current.addDependency(dep);
|
58
|
+
return true;
|
59
|
+
}
|
60
|
+
});
|
61
|
+
parser.plugin("call require.resolve(Weak):context", (expr, param, weak) => {
|
62
|
+
const dep = ContextDependencyHelpers.create(RequireResolveContextDependency, param.range, param, expr, options);
|
63
|
+
if(!dep) return;
|
53
64
|
dep.loc = expr.loc;
|
54
|
-
dep.optional = !!
|
65
|
+
dep.optional = !!parser.scope.inTry;
|
55
66
|
dep.weak = weak;
|
56
|
-
|
67
|
+
parser.state.current.addDependency(dep);
|
57
68
|
return true;
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
|
62
|
-
if(!dep) return;
|
63
|
-
dep.loc = expr.loc;
|
64
|
-
dep.optional = !!this.scope.inTry;
|
65
|
-
dep.weak = weak;
|
66
|
-
this.state.current.addDependency(dep);
|
67
|
-
return true;
|
68
|
-
});
|
69
|
-
};
|
69
|
+
});
|
70
|
+
}
|
71
|
+
}
|
72
|
+
module.exports = RequireResolveDependencyParserPlugin;
|
@@ -2,43 +2,41 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
6
|
-
var ParserHelpers = require("../ParserHelpers");
|
5
|
+
"use strict";
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
const ParserHelpers = require("../ParserHelpers");
|
8
|
+
|
9
|
+
class SystemPlugin {
|
10
|
+
constructor(options) {
|
11
|
+
this.options = options;
|
12
|
+
}
|
13
|
+
|
14
|
+
apply(compiler) {
|
15
|
+
compiler.plugin("compilation", (compilation, params) => {
|
16
|
+
params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
|
17
|
+
|
18
|
+
if(typeof parserOptions.system !== "undefined" && !parserOptions.system)
|
19
|
+
return;
|
12
20
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
parser.plugin("evaluate typeof "
|
22
|
-
|
23
|
-
|
24
|
-
);
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
parser.plugin("typeof System.import", ParserHelpers.toConstantDependency("function"));
|
31
|
-
parser.plugin("evaluate typeof System.import", ParserHelpers.evaluateToString("function"));
|
32
|
-
|
33
|
-
setNotSupported("System.set");
|
34
|
-
setNotSupported("System.get");
|
35
|
-
setNotSupported("System.register");
|
36
|
-
parser.plugin("expression System", function(expr) {
|
37
|
-
var dep = new ConstDependency("{}", expr.range);
|
38
|
-
dep.loc = expr.loc;
|
39
|
-
this.state.current.addDependency(dep);
|
40
|
-
return true;
|
21
|
+
function setNotSupported(name) {
|
22
|
+
parser.plugin("evaluate typeof " + name, ParserHelpers.evaluateToString("undefined"));
|
23
|
+
parser.plugin("expression " + name,
|
24
|
+
ParserHelpers.expressionIsUnsupported(name + " is not supported by webpack.")
|
25
|
+
);
|
26
|
+
}
|
27
|
+
|
28
|
+
parser.plugin("typeof System", ParserHelpers.toConstantDependency(JSON.stringify("object")));
|
29
|
+
parser.plugin("evaluate typeof System", ParserHelpers.evaluateToString("object"));
|
30
|
+
|
31
|
+
parser.plugin("typeof System.import", ParserHelpers.toConstantDependency(JSON.stringify("function")));
|
32
|
+
parser.plugin("evaluate typeof System.import", ParserHelpers.evaluateToString("function"));
|
33
|
+
|
34
|
+
setNotSupported("System.set");
|
35
|
+
setNotSupported("System.get");
|
36
|
+
setNotSupported("System.register");
|
37
|
+
parser.plugin("expression System", ParserHelpers.toConstantDependency("{}"));
|
41
38
|
});
|
42
39
|
});
|
43
|
-
}
|
44
|
-
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
module.exports = SystemPlugin;
|
@@ -2,30 +2,22 @@
|
|
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
|
-
};
|
5
|
+
"use strict";
|
6
|
+
const toErrorCode = err => `var e = new Error(${JSON.stringify(err)}); e.code = 'MODULE_NOT_FOUND';`;
|
7
|
+
|
8
|
+
exports.module = request => `!(function webpackMissingModule() { ${exports.moduleCode(request)} }())`;
|
10
9
|
|
11
10
|
exports.promise = function(request) {
|
12
|
-
|
13
|
-
|
14
|
-
"e.code = 'MODULE_NOT_FOUND'; " +
|
15
|
-
"return e; " +
|
16
|
-
"}())";
|
11
|
+
const errorCode = toErrorCode(`Cannot find module "${request}"`);
|
12
|
+
return `Promise.reject(function webpackMissingModule() { ${errorCode}; return e; }())`;
|
17
13
|
};
|
18
14
|
|
19
15
|
exports.moduleCode = function(request) {
|
20
|
-
|
21
|
-
|
22
|
-
"throw e;";
|
16
|
+
const errorCode = toErrorCode(`Cannot find module "${request}"`);
|
17
|
+
return `${errorCode}; throw e;`;
|
23
18
|
};
|
24
19
|
|
25
20
|
exports.moduleMetaInfo = function(request) {
|
26
|
-
|
27
|
-
|
28
|
-
"e.code = 'MODULE_NOT_FOUND'; " +
|
29
|
-
"throw e; " +
|
30
|
-
"}())";
|
21
|
+
const errorCode = toErrorCode(`Module cannot be imported because no meta info about exports is available "${request}"`);
|
22
|
+
return `!(function webpackMissingModuleMetaInfo() { ${errorCode}; throw e; }())`;
|
31
23
|
};
|
@@ -2,11 +2,14 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
|
5
|
+
"use strict";
|
6
6
|
|
7
|
-
|
7
|
+
const ExternalsPlugin = require("../ExternalsPlugin");
|
8
|
+
|
9
|
+
class NodeTargetPlugin {
|
10
|
+
apply(compiler) {
|
11
|
+
new ExternalsPlugin("commonjs", Object.keys(process.binding("natives"))).apply(compiler);
|
12
|
+
}
|
13
|
+
}
|
8
14
|
|
9
15
|
module.exports = NodeTargetPlugin;
|
10
|
-
NodeTargetPlugin.prototype.apply = function(compiler) {
|
11
|
-
new ExternalsPlugin("commonjs", Object.keys(process.binding("natives"))).apply(compiler);
|
12
|
-
};
|