webpack 2.3.3 → 2.5.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 +148 -133
- package/lib/APIPlugin.js +0 -6
- package/lib/AsyncDependenciesBlock.js +1 -1
- package/lib/AutomaticPrefetchPlugin.js +2 -2
- package/lib/BannerPlugin.js +30 -8
- package/lib/CachePlugin.js +2 -2
- package/lib/CaseSensitiveModulesWarning.js +6 -3
- package/lib/ChunkRenderError.js +3 -1
- package/lib/ChunkTemplate.js +2 -2
- package/lib/Compilation.js +17 -17
- package/lib/Compiler.js +30 -25
- package/lib/ContextModule.js +4 -3
- package/lib/ContextModuleFactory.js +5 -5
- package/lib/DelegatedModule.js +69 -63
- package/lib/DependenciesBlock.js +65 -59
- package/lib/Dependency.js +1 -0
- package/lib/EntryModuleNotFoundError.js +16 -10
- package/lib/ExtendedAPIPlugin.js +7 -2
- package/lib/ExternalModule.js +1 -1
- package/lib/ExternalModuleFactoryPlugin.js +26 -23
- package/lib/FlagDependencyUsagePlugin.js +63 -75
- package/lib/HotModuleReplacement.runtime.js +25 -27
- package/lib/HotModuleReplacementPlugin.js +3 -5
- package/lib/IgnorePlugin.js +48 -17
- package/lib/JsonpChunkTemplatePlugin.js +24 -24
- package/lib/JsonpMainTemplatePlugin.js +182 -182
- package/lib/LibManifestPlugin.js +51 -46
- package/lib/MainTemplate.js +17 -18
- package/lib/Module.js +158 -160
- package/lib/ModuleBuildError.js +4 -2
- package/lib/ModuleDependencyError.js +2 -1
- package/lib/ModuleDependencyWarning.js +2 -1
- package/lib/ModuleError.js +2 -2
- package/lib/ModuleFilenameHelpers.js +27 -27
- package/lib/ModuleNotFoundError.js +3 -1
- package/lib/ModuleParseError.js +6 -4
- package/lib/ModuleWarning.js +2 -2
- package/lib/MultiCompiler.js +3 -4
- package/lib/MultiStats.js +3 -3
- package/lib/MultiWatching.js +2 -2
- package/lib/NamedChunksPlugin.js +30 -0
- package/lib/NodeStuffPlugin.js +80 -79
- package/lib/NormalModule.js +7 -3
- package/lib/NormalModuleFactory.js +244 -240
- package/lib/Parser.js +1256 -1079
- package/lib/ProgressPlugin.js +2 -2
- package/lib/RawModule.js +1 -1
- package/lib/RecordIdsPlugin.js +5 -9
- package/lib/SetVarMainTemplatePlugin.js +1 -1
- package/lib/SourceMapDevToolPlugin.js +153 -157
- package/lib/Stats.js +34 -6
- package/lib/TemplatedPathPlugin.js +1 -0
- package/lib/UnsupportedFeatureWarning.js +2 -1
- package/lib/WebpackError.js +11 -0
- package/lib/WebpackOptionsApply.js +4 -4
- package/lib/WebpackOptionsValidationError.js +2 -3
- package/lib/dependencies/AMDDefineDependency.js +10 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -1
- package/lib/dependencies/AMDPlugin.js +3 -3
- package/lib/dependencies/ContextDependencyHelpers.js +19 -16
- package/lib/dependencies/CriticalDependencyWarning.js +4 -1
- package/lib/dependencies/DepBlockHelpers.js +3 -3
- package/lib/dependencies/HarmonyCompatibilityDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
- package/lib/dependencies/ImportContextDependency.js +2 -1
- package/lib/dependencies/ImportDependenciesBlock.js +2 -2
- package/lib/dependencies/ImportParserPlugin.js +16 -2
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +11 -3
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +42 -13
- package/lib/dependencies/RequireEnsureDependency.js +9 -2
- package/lib/formatLocation.js +44 -27
- package/lib/optimize/AggressiveSplittingPlugin.js +10 -17
- package/lib/optimize/CommonsChunkPlugin.js +2 -2
- package/lib/performance/AssetsOverSizeLimitWarning.js +4 -1
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +5 -1
- package/lib/performance/NoAsyncChunksWarning.js +5 -1
- package/lib/removeAndDo.js +6 -4
- package/lib/util/identifier.js +16 -0
- package/lib/webpack.js +2 -1
- package/package.json +7 -4
- package/schemas/webpackOptionsSchema.json +35 -0
package/lib/NodeStuffPlugin.js
CHANGED
@@ -2,95 +2,96 @@
|
|
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");
|
7
|
-
var ConstDependency = require("./dependencies/ConstDependency");
|
5
|
+
"use strict";
|
8
6
|
|
9
|
-
|
7
|
+
const path = require("path");
|
8
|
+
const ParserHelpers = require("./ParserHelpers");
|
9
|
+
const ConstDependency = require("./dependencies/ConstDependency");
|
10
10
|
|
11
|
-
|
12
|
-
this.options = options;
|
13
|
-
}
|
14
|
-
module.exports = NodeStuffPlugin;
|
15
|
-
NodeStuffPlugin.prototype.apply = function(compiler) {
|
16
|
-
var options = this.options;
|
17
|
-
compiler.plugin("compilation", function(compilation, params) {
|
18
|
-
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
19
|
-
compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
|
11
|
+
const NullFactory = require("./NullFactory");
|
20
12
|
|
21
|
-
|
13
|
+
class NodeStuffPlugin {
|
14
|
+
constructor(options) {
|
15
|
+
this.options = options;
|
16
|
+
}
|
22
17
|
|
23
|
-
|
24
|
-
|
18
|
+
apply(compiler) {
|
19
|
+
const options = this.options;
|
20
|
+
compiler.plugin("compilation", (compilation, params) => {
|
21
|
+
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
22
|
+
compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
|
25
23
|
|
26
|
-
|
27
|
-
if(parserOptions.node)
|
28
|
-
localOptions = Object.assign({}, localOptions, parserOptions.node);
|
24
|
+
params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
|
29
25
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
if(parserOptions.node === false)
|
27
|
+
return;
|
28
|
+
|
29
|
+
let localOptions = options;
|
30
|
+
if(parserOptions.node)
|
31
|
+
localOptions = Object.assign({}, localOptions, parserOptions.node);
|
36
32
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
function setConstant(expressionName, value) {
|
34
|
+
parser.plugin(`expression ${expressionName}`, function() {
|
35
|
+
this.state.current.addVariable(expressionName, JSON.stringify(value));
|
36
|
+
return true;
|
37
|
+
});
|
38
|
+
}
|
39
|
+
|
40
|
+
function setModuleConstant(expressionName, fn) {
|
41
|
+
parser.plugin(`expression ${expressionName}`, function() {
|
42
|
+
this.state.current.addVariable(expressionName, JSON.stringify(fn(this.state.module)));
|
43
|
+
return true;
|
44
|
+
});
|
45
|
+
}
|
46
|
+
const context = compiler.context;
|
47
|
+
if(localOptions.__filename === "mock") {
|
48
|
+
setConstant("__filename", "/index.js");
|
49
|
+
} else if(localOptions.__filename) {
|
50
|
+
setModuleConstant("__filename", module => path.relative(context, module.resource));
|
51
|
+
}
|
52
|
+
parser.plugin("evaluate Identifier __filename", function(expr) {
|
53
|
+
if(!this.state.module) return;
|
54
|
+
const resource = this.state.module.resource;
|
55
|
+
const i = resource.indexOf("?");
|
56
|
+
return ParserHelpers.evaluateToString(i < 0 ? resource : resource.substr(0, i))(expr);
|
41
57
|
});
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
58
|
+
if(localOptions.__dirname === "mock") {
|
59
|
+
setConstant("__dirname", "/");
|
60
|
+
} else if(localOptions.__dirname) {
|
61
|
+
setModuleConstant("__dirname", module => path.relative(context, module.context));
|
62
|
+
}
|
63
|
+
parser.plugin("evaluate Identifier __dirname", function(expr) {
|
64
|
+
if(!this.state.module) return;
|
65
|
+
return ParserHelpers.evaluateToString(this.state.module.context)(expr);
|
49
66
|
});
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
67
|
+
parser.plugin("expression require.main", ParserHelpers.toConstantDependency("__webpack_require__.c[__webpack_require__.s]"));
|
68
|
+
parser.plugin(
|
69
|
+
"expression require.extensions",
|
70
|
+
ParserHelpers.expressionIsUnsupported("require.extensions is not supported by webpack. Use a loader instead.")
|
71
|
+
);
|
72
|
+
parser.plugin("expression module.loaded", ParserHelpers.toConstantDependency("module.l"));
|
73
|
+
parser.plugin("expression module.id", ParserHelpers.toConstantDependency("module.i"));
|
74
|
+
parser.plugin("expression module.exports", function() {
|
75
|
+
const module = this.state.module;
|
76
|
+
const isHarmony = module.meta && module.meta.harmonyModule;
|
77
|
+
if(!isHarmony)
|
78
|
+
return true;
|
62
79
|
});
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
parser.plugin("expression module.loaded", ParserHelpers.toConstantDependency("module.l"));
|
74
|
-
parser.plugin("expression module.id", ParserHelpers.toConstantDependency("module.i"));
|
75
|
-
parser.plugin("expression module.exports", function() {
|
76
|
-
var module = this.state.module;
|
77
|
-
var isHarmony = module.meta && module.meta.harmonyModule;
|
78
|
-
if(!isHarmony)
|
79
|
-
return true;
|
80
|
-
});
|
81
|
-
parser.plugin("evaluate Identifier module.hot", ParserHelpers.evaluateToBoolean(false));
|
82
|
-
parser.plugin("expression module", function() {
|
83
|
-
var module = this.state.module;
|
84
|
-
var isHarmony = module.meta && module.meta.harmonyModule;
|
85
|
-
var moduleJsPath = path.join(__dirname, "..", "buildin", isHarmony ? "harmony-module.js" : "module.js");
|
86
|
-
if(module.context) {
|
87
|
-
moduleJsPath = path.relative(this.state.module.context, moduleJsPath);
|
88
|
-
if(!/^[A-Z]:/i.test(moduleJsPath)) {
|
89
|
-
moduleJsPath = "./" + moduleJsPath.replace(/\\/g, "/");
|
80
|
+
parser.plugin("evaluate Identifier module.hot", ParserHelpers.evaluateToBoolean(false));
|
81
|
+
parser.plugin("expression module", function() {
|
82
|
+
const module = this.state.module;
|
83
|
+
const isHarmony = module.meta && module.meta.harmonyModule;
|
84
|
+
let moduleJsPath = path.join(__dirname, "..", "buildin", isHarmony ? "harmony-module.js" : "module.js");
|
85
|
+
if(module.context) {
|
86
|
+
moduleJsPath = path.relative(this.state.module.context, moduleJsPath);
|
87
|
+
if(!/^[A-Z]:/i.test(moduleJsPath)) {
|
88
|
+
moduleJsPath = `./${moduleJsPath.replace(/\\/g, "/")}`;
|
89
|
+
}
|
90
90
|
}
|
91
|
-
|
92
|
-
|
91
|
+
return ParserHelpers.addParsedVariableToModule(this, "module", `require(${JSON.stringify(moduleJsPath)})(module)`);
|
92
|
+
});
|
93
93
|
});
|
94
94
|
});
|
95
|
-
}
|
96
|
-
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
module.exports = NodeStuffPlugin;
|
package/lib/NormalModule.js
CHANGED
@@ -15,6 +15,7 @@ const ReplaceSource = require("webpack-sources").ReplaceSource;
|
|
15
15
|
const CachedSource = require("webpack-sources").CachedSource;
|
16
16
|
const LineToLineMappedSource = require("webpack-sources").LineToLineMappedSource;
|
17
17
|
|
18
|
+
const WebpackError = require("./WebpackError");
|
18
19
|
const Module = require("./Module");
|
19
20
|
const ModuleParseError = require("./ModuleParseError");
|
20
21
|
const ModuleBuildError = require("./ModuleBuildError");
|
@@ -42,8 +43,7 @@ function contextify(context, request) {
|
|
42
43
|
}).join("!");
|
43
44
|
}
|
44
45
|
|
45
|
-
class NonErrorEmittedError extends
|
46
|
-
|
46
|
+
class NonErrorEmittedError extends WebpackError {
|
47
47
|
constructor(error) {
|
48
48
|
super();
|
49
49
|
|
@@ -257,7 +257,7 @@ class NormalModule extends Module {
|
|
257
257
|
}
|
258
258
|
|
259
259
|
build(options, compilation, resolver, fs, callback) {
|
260
|
-
this.buildTimestamp =
|
260
|
+
this.buildTimestamp = Date.now();
|
261
261
|
this.built = true;
|
262
262
|
this._source = null;
|
263
263
|
this.error = null;
|
@@ -456,6 +456,10 @@ class NormalModule extends Module {
|
|
456
456
|
return new CachedSource(source);
|
457
457
|
}
|
458
458
|
|
459
|
+
originalSource() {
|
460
|
+
return this._source;
|
461
|
+
}
|
462
|
+
|
459
463
|
getHighestTimestamp(keys, timestampsByKey) {
|
460
464
|
let highestTimestamp = 0;
|
461
465
|
for(let i = 0; i < keys.length; i++) {
|