webpack 1.13.3 → 1.14.0
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/LICENSE +22 -22
- package/README.md +310 -310
- package/buildin/amd-define.js +1 -1
- package/buildin/amd-options.js +1 -1
- package/buildin/module.js +10 -10
- package/hot/dev-server.js +63 -63
- package/hot/log-apply-result.js +25 -25
- package/hot/only-dev-server.js +77 -77
- package/hot/poll.js +37 -37
- package/hot/signal.js +65 -65
- package/lib/APIPlugin.js +49 -49
- package/lib/AbstractPlugin.js +22 -22
- package/lib/AmdMainTemplatePlugin.js +43 -43
- package/lib/ArrayMap.js +50 -50
- package/lib/AsyncDependenciesBlock.js +39 -39
- package/lib/AutomaticPrefetchPlugin.js +35 -35
- package/lib/BannerPlugin.js +34 -34
- package/lib/BasicEvaluatedExpression.js +140 -140
- package/lib/CachePlugin.js +43 -43
- package/lib/CaseSensitiveModulesWarning.js +16 -16
- package/lib/Chunk.js +252 -252
- package/lib/ChunkRenderError.js +17 -17
- package/lib/ChunkTemplate.js +37 -37
- package/lib/CompatibilityPlugin.js +42 -42
- package/lib/Compilation.js +891 -891
- package/lib/Compiler.js +407 -407
- package/lib/ConcatSource.js +5 -5
- package/lib/ConstPlugin.js +54 -54
- package/lib/ContextModule.js +130 -130
- package/lib/ContextModuleFactory.js +132 -132
- package/lib/ContextReplacementPlugin.js +93 -93
- package/lib/CriticalDependenciesWarning.js +24 -24
- package/lib/DefinePlugin.js +126 -126
- package/lib/DelegatedModule.js +69 -69
- package/lib/DelegatedModuleFactoryPlugin.js +51 -51
- package/lib/DelegatedPlugin.js +21 -21
- package/lib/DependenciesBlock.js +57 -57
- package/lib/DependenciesBlockVariable.js +41 -41
- package/lib/Dependency.js +54 -54
- package/lib/DllEntryPlugin.js +32 -32
- package/lib/DllModule.js +55 -55
- package/lib/DllModuleFactory.js +18 -18
- package/lib/DllPlugin.js +30 -30
- package/lib/DllReferencePlugin.js +26 -26
- package/lib/EntryModuleNotFoundError.js +15 -15
- package/lib/EntryOptionPlugin.js +28 -28
- package/lib/EnvironmentPlugin.js +28 -28
- package/lib/EvalDevToolModulePlugin.js +17 -17
- package/lib/EvalDevToolModuleTemplatePlugin.js +29 -29
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +68 -68
- package/lib/EvalSourceMapDevToolPlugin.js +25 -25
- package/lib/ExtendedAPIPlugin.js +45 -45
- package/lib/ExternalModule.js +89 -89
- package/lib/ExternalModuleFactoryPlugin.js +86 -86
- package/lib/ExternalsPlugin.js +16 -16
- package/lib/FunctionModulePlugin.js +18 -18
- package/lib/FunctionModuleTemplatePlugin.js +39 -39
- package/lib/HotModuleReplacement.runtime.js +486 -486
- package/lib/HotModuleReplacementPlugin.js +223 -223
- package/lib/HotUpdateChunkTemplate.js +28 -28
- package/lib/IgnorePlugin.js +32 -32
- package/lib/JsonpChunkTemplatePlugin.js +26 -26
- package/lib/JsonpExportMainTemplatePlugin.js +28 -28
- package/lib/JsonpHotUpdateChunkTemplatePlugin.js +26 -26
- package/lib/JsonpMainTemplate.runtime.js +56 -56
- package/lib/JsonpMainTemplatePlugin.js +162 -162
- package/lib/JsonpTemplatePlugin.js +17 -17
- package/lib/LibManifestPlugin.js +49 -49
- package/lib/LibraryTemplatePlugin.js +77 -77
- package/lib/LoaderTargetPlugin.js +16 -16
- package/lib/MainTemplate.js +169 -169
- package/lib/MemoryOutputFileSystem.js +5 -5
- package/lib/Module.js +116 -116
- package/lib/ModuleFilenameHelpers.js +157 -157
- package/lib/ModuleNotFoundError.js +17 -17
- package/lib/ModuleParseError.js +26 -26
- package/lib/ModuleParserHelpers.js +21 -21
- package/lib/ModuleReason.js +9 -9
- package/lib/ModuleTemplate.js +23 -23
- package/lib/MovedToPluginWarningPlugin.js +17 -17
- package/lib/MultiCompiler.js +166 -166
- package/lib/MultiEntryPlugin.js +31 -31
- package/lib/MultiModule.js +71 -71
- package/lib/MultiModuleFactory.js +18 -18
- package/lib/NamedModulesPlugin.js +21 -21
- package/lib/NewWatchingPlugin.js +12 -12
- package/lib/NoErrorsPlugin.js +18 -18
- package/lib/NodeStuffPlugin.js +99 -99
- package/lib/NormalModule.js +322 -322
- package/lib/NormalModuleFactory.js +171 -171
- package/lib/NormalModuleReplacementPlugin.js +40 -40
- package/lib/NullFactory.js +10 -10
- package/lib/OldWatchingPlugin.js +14 -14
- package/lib/OptionsApply.js +10 -10
- package/lib/OriginalSource.js +5 -5
- package/lib/Parser.js +938 -938
- package/lib/PrefetchPlugin.js +25 -25
- package/lib/ProgressPlugin.js +80 -80
- package/lib/ProvidePlugin.js +48 -48
- package/lib/RawModule.js +65 -65
- package/lib/RawSource.js +5 -5
- package/lib/RecordIdsPlugin.js +130 -130
- package/lib/RequestShortener.js +56 -56
- package/lib/RequireJsStuffPlugin.js +38 -38
- package/lib/ResolverPlugin.js +34 -34
- package/lib/SetVarMainTemplatePlugin.js +36 -36
- package/lib/SingleEntryPlugin.js +24 -24
- package/lib/Source.js +5 -5
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +33 -33
- package/lib/SourceMapDevToolPlugin.js +168 -168
- package/lib/SourceMapSource.js +5 -5
- package/lib/Stats.js +732 -732
- package/lib/Template.js +119 -119
- package/lib/TemplatedPathPlugin.js +111 -111
- package/lib/UmdMainTemplatePlugin.js +146 -146
- package/lib/UnsupportedFeatureWarning.js +14 -14
- package/lib/WarnCaseSensitiveModulesPlugin.js +27 -27
- package/lib/WatchIgnorePlugin.js +45 -45
- package/lib/WebpackOptionsApply.js +376 -376
- package/lib/WebpackOptionsDefaulter.js +112 -112
- package/lib/dependencies/AMDDefineDependency.js +63 -63
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +240 -240
- package/lib/dependencies/AMDPlugin.js +115 -115
- package/lib/dependencies/AMDRequireArrayDependency.js +34 -34
- package/lib/dependencies/AMDRequireContextDependency.js +18 -18
- package/lib/dependencies/AMDRequireDependenciesBlock.js +25 -25
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +145 -145
- package/lib/dependencies/AMDRequireDependency.js +64 -64
- package/lib/dependencies/AMDRequireItemDependency.js +17 -17
- package/lib/dependencies/CommonJsPlugin.js +93 -93
- package/lib/dependencies/CommonJsRequireContextDependency.js +18 -18
- package/lib/dependencies/CommonJsRequireDependency.js +17 -17
- package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +91 -91
- package/lib/dependencies/ConstDependency.js +29 -29
- package/lib/dependencies/ContextDependency.js +24 -24
- package/lib/dependencies/ContextDependencyHelpers.js +34 -34
- package/lib/dependencies/ContextDependencyTemplateAsId.js +22 -22
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +31 -31
- package/lib/dependencies/ContextElementDependency.js +17 -17
- package/lib/dependencies/DelegatedSourceDependency.js +14 -14
- package/lib/dependencies/DepBlockHelpers.js +41 -41
- package/lib/dependencies/DllEntryDependency.js +17 -17
- package/lib/dependencies/LabeledExportsDependency.js +21 -21
- package/lib/dependencies/LabeledModuleDependency.js +36 -36
- package/lib/dependencies/LabeledModuleDependencyParserPlugin.js +76 -76
- package/lib/dependencies/LabeledModulesPlugin.js +26 -26
- package/lib/dependencies/LoaderDependency.js +14 -14
- package/lib/dependencies/LoaderPlugin.js +61 -61
- package/lib/dependencies/LocalModule.js +19 -19
- package/lib/dependencies/LocalModuleDependency.js +23 -23
- package/lib/dependencies/LocalModulesHelpers.js +43 -43
- package/lib/dependencies/ModuleDependency.js +20 -20
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +22 -22
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +22 -22
- package/lib/dependencies/ModuleHotAcceptDependency.js +18 -18
- package/lib/dependencies/ModuleHotDeclineDependency.js +18 -18
- package/lib/dependencies/MultiEntryDependency.js +16 -16
- package/lib/dependencies/NullDependency.js +17 -17
- package/lib/dependencies/NullDependencyTemplate.js +8 -8
- package/lib/dependencies/PrefetchDependency.js +14 -14
- package/lib/dependencies/RequireContextDependency.js +17 -17
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +33 -33
- package/lib/dependencies/RequireContextPlugin.js +64 -64
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +20 -20
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +66 -66
- package/lib/dependencies/RequireEnsureDependency.js +29 -29
- package/lib/dependencies/RequireEnsureItemDependency.js +16 -16
- package/lib/dependencies/RequireEnsurePlugin.js +38 -38
- package/lib/dependencies/RequireHeaderDependency.js +25 -25
- package/lib/dependencies/RequireIncludeDependency.js +25 -25
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +18 -18
- package/lib/dependencies/RequireIncludePlugin.js +31 -31
- package/lib/dependencies/RequireResolveContextDependency.js +18 -18
- package/lib/dependencies/RequireResolveDependency.js +17 -17
- package/lib/dependencies/RequireResolveDependencyParserPlugin.js +69 -69
- package/lib/dependencies/RequireResolveHeaderDependency.js +25 -25
- package/lib/dependencies/SingleEntryDependency.js +14 -14
- package/lib/dependencies/TemplateArgumentDependency.js +26 -26
- package/lib/dependencies/WebpackMissingModule.js +23 -23
- package/lib/dependencies/getFunctionExpression.js +43 -43
- package/lib/node/NodeChunkTemplatePlugin.js +22 -22
- package/lib/node/NodeEnvironmentPlugin.js +25 -25
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +24 -24
- package/lib/node/NodeMainTemplate.runtime.js +20 -20
- package/lib/node/NodeMainTemplateAsync.runtime.js +34 -34
- package/lib/node/NodeMainTemplatePlugin.js +164 -164
- package/lib/node/NodeOutputFileSystem.js +17 -17
- package/lib/node/NodeSourcePlugin.js +85 -75
- package/lib/node/NodeTargetPlugin.js +12 -12
- package/lib/node/NodeTemplatePlugin.js +21 -21
- package/lib/node/NodeWatchFileSystem.js +65 -65
- package/lib/node/OldNodeWatchFileSystem.js +265 -265
- package/lib/optimize/AggressiveMergingPlugin.js +115 -115
- package/lib/optimize/CommonsChunkPlugin.js +178 -178
- package/lib/optimize/DedupePlugin.js +227 -227
- package/lib/optimize/FlagIncludedChunksPlugin.js +24 -24
- package/lib/optimize/LimitChunkCountPlugin.js +55 -55
- package/lib/optimize/MergeDuplicateChunksPlugin.js +30 -30
- package/lib/optimize/MinChunkSizePlugin.js +61 -61
- package/lib/optimize/OccurenceOrderPlugin.js +5 -5
- package/lib/optimize/OccurrenceOrderPlugin.js +91 -91
- package/lib/optimize/RemoveEmptyChunksPlugin.js +19 -19
- package/lib/optimize/RemoveParentModulesPlugin.js +50 -50
- package/lib/optimize/UglifyJsPlugin.js +146 -146
- package/lib/removeAndDo.js +13 -13
- package/lib/web/WebEnvironmentPlugin.js +16 -16
- package/lib/webpack.js +113 -113
- package/lib/webpack.web.js +27 -27
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +26 -26
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +78 -78
- package/lib/webworker/WebWorkerTemplatePlugin.js +15 -15
- package/package.json +4 -4
package/lib/NormalModule.js
CHANGED
@@ -1,322 +1,322 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
var path = require("path");
|
6
|
-
var Module = require("./Module");
|
7
|
-
var NormalModuleMixin = require("webpack-core/lib/NormalModuleMixin");
|
8
|
-
var SourceMapSource = require("webpack-core/lib/SourceMapSource");
|
9
|
-
var OriginalSource = require("webpack-core/lib/OriginalSource");
|
10
|
-
var RawSource = require("webpack-core/lib/RawSource");
|
11
|
-
var ReplaceSource = require("webpack-core/lib/ReplaceSource");
|
12
|
-
var CachedSource = require("webpack-core/lib/CachedSource");
|
13
|
-
var ModuleParseError = require("./ModuleParseError");
|
14
|
-
var TemplateArgumentDependency = require("./dependencies/TemplateArgumentDependency");
|
15
|
-
var AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
|
16
|
-
|
17
|
-
function NormalModule(request, userRequest, rawRequest, loaders, resource, parser) {
|
18
|
-
Module.call(this);
|
19
|
-
this.request = request;
|
20
|
-
this.userRequest = userRequest;
|
21
|
-
this.rawRequest = rawRequest;
|
22
|
-
this.parser = parser;
|
23
|
-
NormalModuleMixin.call(this, loaders, resource);
|
24
|
-
this.meta = {};
|
25
|
-
this.assets = {};
|
26
|
-
this.built = false;
|
27
|
-
this._cachedSource = null;
|
28
|
-
}
|
29
|
-
module.exports = NormalModule;
|
30
|
-
|
31
|
-
NormalModule.prototype = Object.create(Module.prototype);
|
32
|
-
NormalModuleMixin.mixin(NormalModule.prototype);
|
33
|
-
|
34
|
-
NormalModule.prototype.identifier = function() {
|
35
|
-
return this.request;
|
36
|
-
};
|
37
|
-
|
38
|
-
NormalModule.prototype.readableIdentifier = function(requestShortener) {
|
39
|
-
return requestShortener.shorten(this.userRequest);
|
40
|
-
};
|
41
|
-
|
42
|
-
function contextify(options, request) {
|
43
|
-
return request.split("!").map(function(r) {
|
44
|
-
var rp = path.relative(options.context, r);
|
45
|
-
if(path.sep === "\\")
|
46
|
-
rp = rp.replace(/\\/g, "/");
|
47
|
-
if(rp.indexOf("../") !== 0)
|
48
|
-
rp = "./" + rp;
|
49
|
-
return rp;
|
50
|
-
}).join("!");
|
51
|
-
}
|
52
|
-
|
53
|
-
NormalModule.prototype.libIdent = function(options) {
|
54
|
-
return contextify(options, this.userRequest);
|
55
|
-
};
|
56
|
-
|
57
|
-
NormalModule.prototype.fillLoaderContext = function fillLoaderContext(loaderContext, options, compilation) {
|
58
|
-
loaderContext.webpack = true;
|
59
|
-
loaderContext.sourceMap = !!this.useSourceMap;
|
60
|
-
loaderContext.emitFile = function(name, content, sourceMap) {
|
61
|
-
if(typeof sourceMap === "string") {
|
62
|
-
this.assets[name] = new OriginalSource(content, sourceMap);
|
63
|
-
} else if(sourceMap) {
|
64
|
-
this.assets[name] = new SourceMapSource(content, name, sourceMap);
|
65
|
-
} else {
|
66
|
-
this.assets[name] = new RawSource(content);
|
67
|
-
}
|
68
|
-
}.bind(this);
|
69
|
-
loaderContext._module = this;
|
70
|
-
loaderContext._compilation = compilation;
|
71
|
-
loaderContext._compiler = compilation.compiler;
|
72
|
-
loaderContext.fs = compilation.compiler.inputFileSystem;
|
73
|
-
compilation.applyPlugins("normal-module-loader", loaderContext, this);
|
74
|
-
};
|
75
|
-
|
76
|
-
NormalModule.prototype.disconnect = function disconnect() {
|
77
|
-
this.built = false;
|
78
|
-
Module.prototype.disconnect.call(this);
|
79
|
-
};
|
80
|
-
|
81
|
-
NormalModule.prototype.build = function build(options, compilation, resolver, fs, callback) {
|
82
|
-
this.buildTimestamp = new Date().getTime();
|
83
|
-
this.built = true;
|
84
|
-
return this.doBuild(options, compilation, resolver, fs, function(err) {
|
85
|
-
if(err) return callback(err);
|
86
|
-
this.dependencies.length = 0;
|
87
|
-
this.variables.length = 0;
|
88
|
-
this.blocks.length = 0;
|
89
|
-
this._cachedSource = null;
|
90
|
-
if(options.module && options.module.noParse) {
|
91
|
-
if(Array.isArray(options.module.noParse)) {
|
92
|
-
if(options.module.noParse.some(function(regExp) {
|
93
|
-
return typeof regExp === "string" ?
|
94
|
-
this.request.indexOf(regExp) === 0 :
|
95
|
-
regExp.test(this.request);
|
96
|
-
}, this)) return callback();
|
97
|
-
} else if(typeof options.module.noParse === "string" ?
|
98
|
-
this.request.indexOf(options.module.noParse) === 0 :
|
99
|
-
options.module.noParse.test(this.request)) {
|
100
|
-
return callback();
|
101
|
-
}
|
102
|
-
}
|
103
|
-
try {
|
104
|
-
this.parser.parse(this._source.source(), {
|
105
|
-
current: this,
|
106
|
-
module: this,
|
107
|
-
compilation: compilation,
|
108
|
-
options: options
|
109
|
-
});
|
110
|
-
} catch(e) {
|
111
|
-
var source = this._source.source();
|
112
|
-
this._source = null;
|
113
|
-
return callback(new ModuleParseError(this, source, e));
|
114
|
-
}
|
115
|
-
return callback();
|
116
|
-
}.bind(this));
|
117
|
-
};
|
118
|
-
|
119
|
-
NormalModule.prototype.source = function(dependencyTemplates, outputOptions, requestShortener) {
|
120
|
-
var hash = require("crypto").createHash("md5");
|
121
|
-
this.updateHash(hash);
|
122
|
-
hash = hash.digest("hex");
|
123
|
-
if(this._cachedSource && this._cachedSource.hash === hash) {
|
124
|
-
return this._cachedSource.source;
|
125
|
-
}
|
126
|
-
var _source = this._source;
|
127
|
-
if(!_source) return new RawSource("throw new Error('No source available');");
|
128
|
-
var source = new ReplaceSource(_source);
|
129
|
-
this._cachedSource = {
|
130
|
-
source: source,
|
131
|
-
hash: hash
|
132
|
-
};
|
133
|
-
var topLevelBlock = this;
|
134
|
-
|
135
|
-
function doDep(dep) {
|
136
|
-
var template = dependencyTemplates.get(dep.constructor);
|
137
|
-
if(!template) throw new Error("No template for dependency: " + dep.constructor.name);
|
138
|
-
template.apply(dep, source, outputOptions, requestShortener, dependencyTemplates);
|
139
|
-
}
|
140
|
-
|
141
|
-
function doVariable(vars, variable) {
|
142
|
-
var name = variable.name;
|
143
|
-
var expr = variable.expressionSource(dependencyTemplates, outputOptions, requestShortener);
|
144
|
-
vars.push({
|
145
|
-
name: name,
|
146
|
-
expression: expr
|
147
|
-
});
|
148
|
-
}
|
149
|
-
|
150
|
-
function doBlock(block) {
|
151
|
-
block.dependencies.forEach(doDep);
|
152
|
-
block.blocks.forEach(doBlock);
|
153
|
-
if(block.variables.length > 0) {
|
154
|
-
var vars = [];
|
155
|
-
block.variables.forEach(doVariable.bind(null, vars));
|
156
|
-
var varNames = [];
|
157
|
-
var varExpressions = [];
|
158
|
-
var varStartCode = "";
|
159
|
-
var varEndCode = "";
|
160
|
-
|
161
|
-
function emitFunction() {
|
162
|
-
if(varNames.length === 0) return;
|
163
|
-
|
164
|
-
varStartCode += "/* WEBPACK VAR INJECTION */(function(" + varNames.join(", ") + ") {";
|
165
|
-
// exports === this in the topLevelBlock, but exports do compress better...
|
166
|
-
varEndCode = (topLevelBlock === block ? "}.call(exports, " : "}.call(this, ") +
|
167
|
-
varExpressions.map(function(e) {
|
168
|
-
return e.source();
|
169
|
-
}).join(", ") + "))" + varEndCode;
|
170
|
-
|
171
|
-
varNames.length = 0;
|
172
|
-
varExpressions.length = 0;
|
173
|
-
}
|
174
|
-
vars.forEach(function(v) {
|
175
|
-
if(varNames.indexOf(v.name) >= 0) emitFunction();
|
176
|
-
varNames.push(v.name);
|
177
|
-
varExpressions.push(v.expression);
|
178
|
-
});
|
179
|
-
emitFunction();
|
180
|
-
var start = block.range ? block.range[0] : 0;
|
181
|
-
var end = block.range ? block.range[1] : _source.size();
|
182
|
-
if(varStartCode) source.insert(start + 0.5, varStartCode);
|
183
|
-
if(varEndCode) source.insert(end + 0.5, "\n/* WEBPACK VAR INJECTION */" + varEndCode);
|
184
|
-
}
|
185
|
-
}
|
186
|
-
doBlock(this);
|
187
|
-
return new CachedSource(source);
|
188
|
-
};
|
189
|
-
|
190
|
-
NormalModule.prototype.needRebuild = function needRebuild(fileTimestamps, contextTimestamps) {
|
191
|
-
var timestamp = 0;
|
192
|
-
this.fileDependencies.forEach(function(file) {
|
193
|
-
var ts = fileTimestamps[file];
|
194
|
-
if(!ts) timestamp = Infinity;
|
195
|
-
if(ts > timestamp) timestamp = ts;
|
196
|
-
});
|
197
|
-
this.contextDependencies.forEach(function(context) {
|
198
|
-
var ts = contextTimestamps[context];
|
199
|
-
if(!ts) timestamp = Infinity;
|
200
|
-
if(ts > timestamp) timestamp = ts;
|
201
|
-
});
|
202
|
-
return timestamp >= this.buildTimestamp;
|
203
|
-
};
|
204
|
-
|
205
|
-
NormalModule.prototype.size = function() {
|
206
|
-
return this._source ? this._source.size() : -1;
|
207
|
-
};
|
208
|
-
|
209
|
-
NormalModule.prototype.updateHash = function(hash) {
|
210
|
-
if(this._source) {
|
211
|
-
hash.update("source");
|
212
|
-
this._source.updateHash(hash);
|
213
|
-
} else
|
214
|
-
hash.update("null");
|
215
|
-
hash.update("meta");
|
216
|
-
hash.update(JSON.stringify(this.meta));
|
217
|
-
Module.prototype.updateHash.call(this, hash);
|
218
|
-
};
|
219
|
-
|
220
|
-
NormalModule.prototype.getSourceHash = function() {
|
221
|
-
if(!this._source) return "";
|
222
|
-
var hash = require("crypto").createHash("md5");
|
223
|
-
hash.update(this._source.source());
|
224
|
-
return hash.digest("hex");
|
225
|
-
};
|
226
|
-
|
227
|
-
NormalModule.prototype.getAllModuleDependencies = function() {
|
228
|
-
var list = [];
|
229
|
-
|
230
|
-
function doDep(dep) {
|
231
|
-
if(dep.module && list.indexOf(dep.module) < 0)
|
232
|
-
list.push(dep.module);
|
233
|
-
}
|
234
|
-
|
235
|
-
function doVariable(variable) {
|
236
|
-
variable.dependencies.forEach(doDep);
|
237
|
-
}
|
238
|
-
|
239
|
-
function doBlock(block) {
|
240
|
-
block.variables.forEach(doVariable);
|
241
|
-
block.dependencies.forEach(doDep);
|
242
|
-
block.blocks.forEach(doBlock);
|
243
|
-
}
|
244
|
-
doBlock(this);
|
245
|
-
return list;
|
246
|
-
};
|
247
|
-
|
248
|
-
NormalModule.prototype.createTemplate = function(keepModules, roots) {
|
249
|
-
roots.sort(function(a, b) {
|
250
|
-
var ia = a.identifier();
|
251
|
-
var ib = b.identifier();
|
252
|
-
if(ia < ib) return -1;
|
253
|
-
if(ib < ia) return 1;
|
254
|
-
return 0;
|
255
|
-
});
|
256
|
-
var template = new NormalModule("", "", "", [], "", null);
|
257
|
-
template._source = this._source;
|
258
|
-
template.built = this.built;
|
259
|
-
template.templateModules = keepModules;
|
260
|
-
template._templateOrigin = this;
|
261
|
-
template.readableIdentifier = function() {
|
262
|
-
return "template of " + this._templateOrigin.id + " referencing " + keepModules.map(function(m) {
|
263
|
-
return m.id;
|
264
|
-
}).join(", ");
|
265
|
-
};
|
266
|
-
template.identifier = function() {
|
267
|
-
var array = roots.map(function(m) {
|
268
|
-
return m.identifier();
|
269
|
-
});
|
270
|
-
array.sort();
|
271
|
-
return array.join("|");
|
272
|
-
};
|
273
|
-
var args = template.arguments = [];
|
274
|
-
|
275
|
-
function doDeps(deps) {
|
276
|
-
return deps.map(function(dep) {
|
277
|
-
if(dep.module && keepModules.indexOf(dep.module) < 0) {
|
278
|
-
var argName = "__webpack_module_template_argument_" + args.length + "__";
|
279
|
-
args.push(argName);
|
280
|
-
return new TemplateArgumentDependency(argName, dep);
|
281
|
-
} else {
|
282
|
-
return dep;
|
283
|
-
}
|
284
|
-
});
|
285
|
-
}
|
286
|
-
|
287
|
-
function doBlock(block, newBlock) {
|
288
|
-
block.variables.forEach(function(variable) {
|
289
|
-
var newDependencies = doDeps(variable.dependencies);
|
290
|
-
newBlock.addVariable(variable.name, variable.expression, newDependencies);
|
291
|
-
});
|
292
|
-
newBlock.dependencies = doDeps(block.dependencies);
|
293
|
-
block.blocks.forEach(function(childBlock) {
|
294
|
-
var newChildBlock = new AsyncDependenciesBlock(childBlock.name, childBlock.module, childBlock.loc);
|
295
|
-
newBlock.addBlock(newChildBlock);
|
296
|
-
doBlock(childBlock, newChildBlock);
|
297
|
-
});
|
298
|
-
}
|
299
|
-
doBlock(this, template);
|
300
|
-
return template;
|
301
|
-
};
|
302
|
-
|
303
|
-
NormalModule.prototype.getTemplateArguments = function(keepModules) {
|
304
|
-
var list = [];
|
305
|
-
|
306
|
-
function doDep(dep) {
|
307
|
-
if(dep.module && keepModules.indexOf(dep.module) < 0)
|
308
|
-
list.push(dep.module);
|
309
|
-
}
|
310
|
-
|
311
|
-
function doVariable(variable) {
|
312
|
-
variable.dependencies.forEach(doDep);
|
313
|
-
}
|
314
|
-
|
315
|
-
function doBlock(block) {
|
316
|
-
block.variables.forEach(doVariable);
|
317
|
-
block.dependencies.forEach(doDep);
|
318
|
-
block.blocks.forEach(doBlock);
|
319
|
-
}
|
320
|
-
doBlock(this);
|
321
|
-
return list;
|
322
|
-
};
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
var path = require("path");
|
6
|
+
var Module = require("./Module");
|
7
|
+
var NormalModuleMixin = require("webpack-core/lib/NormalModuleMixin");
|
8
|
+
var SourceMapSource = require("webpack-core/lib/SourceMapSource");
|
9
|
+
var OriginalSource = require("webpack-core/lib/OriginalSource");
|
10
|
+
var RawSource = require("webpack-core/lib/RawSource");
|
11
|
+
var ReplaceSource = require("webpack-core/lib/ReplaceSource");
|
12
|
+
var CachedSource = require("webpack-core/lib/CachedSource");
|
13
|
+
var ModuleParseError = require("./ModuleParseError");
|
14
|
+
var TemplateArgumentDependency = require("./dependencies/TemplateArgumentDependency");
|
15
|
+
var AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
|
16
|
+
|
17
|
+
function NormalModule(request, userRequest, rawRequest, loaders, resource, parser) {
|
18
|
+
Module.call(this);
|
19
|
+
this.request = request;
|
20
|
+
this.userRequest = userRequest;
|
21
|
+
this.rawRequest = rawRequest;
|
22
|
+
this.parser = parser;
|
23
|
+
NormalModuleMixin.call(this, loaders, resource);
|
24
|
+
this.meta = {};
|
25
|
+
this.assets = {};
|
26
|
+
this.built = false;
|
27
|
+
this._cachedSource = null;
|
28
|
+
}
|
29
|
+
module.exports = NormalModule;
|
30
|
+
|
31
|
+
NormalModule.prototype = Object.create(Module.prototype);
|
32
|
+
NormalModuleMixin.mixin(NormalModule.prototype);
|
33
|
+
|
34
|
+
NormalModule.prototype.identifier = function() {
|
35
|
+
return this.request;
|
36
|
+
};
|
37
|
+
|
38
|
+
NormalModule.prototype.readableIdentifier = function(requestShortener) {
|
39
|
+
return requestShortener.shorten(this.userRequest);
|
40
|
+
};
|
41
|
+
|
42
|
+
function contextify(options, request) {
|
43
|
+
return request.split("!").map(function(r) {
|
44
|
+
var rp = path.relative(options.context, r);
|
45
|
+
if(path.sep === "\\")
|
46
|
+
rp = rp.replace(/\\/g, "/");
|
47
|
+
if(rp.indexOf("../") !== 0)
|
48
|
+
rp = "./" + rp;
|
49
|
+
return rp;
|
50
|
+
}).join("!");
|
51
|
+
}
|
52
|
+
|
53
|
+
NormalModule.prototype.libIdent = function(options) {
|
54
|
+
return contextify(options, this.userRequest);
|
55
|
+
};
|
56
|
+
|
57
|
+
NormalModule.prototype.fillLoaderContext = function fillLoaderContext(loaderContext, options, compilation) {
|
58
|
+
loaderContext.webpack = true;
|
59
|
+
loaderContext.sourceMap = !!this.useSourceMap;
|
60
|
+
loaderContext.emitFile = function(name, content, sourceMap) {
|
61
|
+
if(typeof sourceMap === "string") {
|
62
|
+
this.assets[name] = new OriginalSource(content, sourceMap);
|
63
|
+
} else if(sourceMap) {
|
64
|
+
this.assets[name] = new SourceMapSource(content, name, sourceMap);
|
65
|
+
} else {
|
66
|
+
this.assets[name] = new RawSource(content);
|
67
|
+
}
|
68
|
+
}.bind(this);
|
69
|
+
loaderContext._module = this;
|
70
|
+
loaderContext._compilation = compilation;
|
71
|
+
loaderContext._compiler = compilation.compiler;
|
72
|
+
loaderContext.fs = compilation.compiler.inputFileSystem;
|
73
|
+
compilation.applyPlugins("normal-module-loader", loaderContext, this);
|
74
|
+
};
|
75
|
+
|
76
|
+
NormalModule.prototype.disconnect = function disconnect() {
|
77
|
+
this.built = false;
|
78
|
+
Module.prototype.disconnect.call(this);
|
79
|
+
};
|
80
|
+
|
81
|
+
NormalModule.prototype.build = function build(options, compilation, resolver, fs, callback) {
|
82
|
+
this.buildTimestamp = new Date().getTime();
|
83
|
+
this.built = true;
|
84
|
+
return this.doBuild(options, compilation, resolver, fs, function(err) {
|
85
|
+
if(err) return callback(err);
|
86
|
+
this.dependencies.length = 0;
|
87
|
+
this.variables.length = 0;
|
88
|
+
this.blocks.length = 0;
|
89
|
+
this._cachedSource = null;
|
90
|
+
if(options.module && options.module.noParse) {
|
91
|
+
if(Array.isArray(options.module.noParse)) {
|
92
|
+
if(options.module.noParse.some(function(regExp) {
|
93
|
+
return typeof regExp === "string" ?
|
94
|
+
this.request.indexOf(regExp) === 0 :
|
95
|
+
regExp.test(this.request);
|
96
|
+
}, this)) return callback();
|
97
|
+
} else if(typeof options.module.noParse === "string" ?
|
98
|
+
this.request.indexOf(options.module.noParse) === 0 :
|
99
|
+
options.module.noParse.test(this.request)) {
|
100
|
+
return callback();
|
101
|
+
}
|
102
|
+
}
|
103
|
+
try {
|
104
|
+
this.parser.parse(this._source.source(), {
|
105
|
+
current: this,
|
106
|
+
module: this,
|
107
|
+
compilation: compilation,
|
108
|
+
options: options
|
109
|
+
});
|
110
|
+
} catch(e) {
|
111
|
+
var source = this._source.source();
|
112
|
+
this._source = null;
|
113
|
+
return callback(new ModuleParseError(this, source, e));
|
114
|
+
}
|
115
|
+
return callback();
|
116
|
+
}.bind(this));
|
117
|
+
};
|
118
|
+
|
119
|
+
NormalModule.prototype.source = function(dependencyTemplates, outputOptions, requestShortener) {
|
120
|
+
var hash = require("crypto").createHash("md5");
|
121
|
+
this.updateHash(hash);
|
122
|
+
hash = hash.digest("hex");
|
123
|
+
if(this._cachedSource && this._cachedSource.hash === hash) {
|
124
|
+
return this._cachedSource.source;
|
125
|
+
}
|
126
|
+
var _source = this._source;
|
127
|
+
if(!_source) return new RawSource("throw new Error('No source available');");
|
128
|
+
var source = new ReplaceSource(_source);
|
129
|
+
this._cachedSource = {
|
130
|
+
source: source,
|
131
|
+
hash: hash
|
132
|
+
};
|
133
|
+
var topLevelBlock = this;
|
134
|
+
|
135
|
+
function doDep(dep) {
|
136
|
+
var template = dependencyTemplates.get(dep.constructor);
|
137
|
+
if(!template) throw new Error("No template for dependency: " + dep.constructor.name);
|
138
|
+
template.apply(dep, source, outputOptions, requestShortener, dependencyTemplates);
|
139
|
+
}
|
140
|
+
|
141
|
+
function doVariable(vars, variable) {
|
142
|
+
var name = variable.name;
|
143
|
+
var expr = variable.expressionSource(dependencyTemplates, outputOptions, requestShortener);
|
144
|
+
vars.push({
|
145
|
+
name: name,
|
146
|
+
expression: expr
|
147
|
+
});
|
148
|
+
}
|
149
|
+
|
150
|
+
function doBlock(block) {
|
151
|
+
block.dependencies.forEach(doDep);
|
152
|
+
block.blocks.forEach(doBlock);
|
153
|
+
if(block.variables.length > 0) {
|
154
|
+
var vars = [];
|
155
|
+
block.variables.forEach(doVariable.bind(null, vars));
|
156
|
+
var varNames = [];
|
157
|
+
var varExpressions = [];
|
158
|
+
var varStartCode = "";
|
159
|
+
var varEndCode = "";
|
160
|
+
|
161
|
+
function emitFunction() {
|
162
|
+
if(varNames.length === 0) return;
|
163
|
+
|
164
|
+
varStartCode += "/* WEBPACK VAR INJECTION */(function(" + varNames.join(", ") + ") {";
|
165
|
+
// exports === this in the topLevelBlock, but exports do compress better...
|
166
|
+
varEndCode = (topLevelBlock === block ? "}.call(exports, " : "}.call(this, ") +
|
167
|
+
varExpressions.map(function(e) {
|
168
|
+
return e.source();
|
169
|
+
}).join(", ") + "))" + varEndCode;
|
170
|
+
|
171
|
+
varNames.length = 0;
|
172
|
+
varExpressions.length = 0;
|
173
|
+
}
|
174
|
+
vars.forEach(function(v) {
|
175
|
+
if(varNames.indexOf(v.name) >= 0) emitFunction();
|
176
|
+
varNames.push(v.name);
|
177
|
+
varExpressions.push(v.expression);
|
178
|
+
});
|
179
|
+
emitFunction();
|
180
|
+
var start = block.range ? block.range[0] : 0;
|
181
|
+
var end = block.range ? block.range[1] : _source.size();
|
182
|
+
if(varStartCode) source.insert(start + 0.5, varStartCode);
|
183
|
+
if(varEndCode) source.insert(end + 0.5, "\n/* WEBPACK VAR INJECTION */" + varEndCode);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
doBlock(this);
|
187
|
+
return new CachedSource(source);
|
188
|
+
};
|
189
|
+
|
190
|
+
NormalModule.prototype.needRebuild = function needRebuild(fileTimestamps, contextTimestamps) {
|
191
|
+
var timestamp = 0;
|
192
|
+
this.fileDependencies.forEach(function(file) {
|
193
|
+
var ts = fileTimestamps[file];
|
194
|
+
if(!ts) timestamp = Infinity;
|
195
|
+
if(ts > timestamp) timestamp = ts;
|
196
|
+
});
|
197
|
+
this.contextDependencies.forEach(function(context) {
|
198
|
+
var ts = contextTimestamps[context];
|
199
|
+
if(!ts) timestamp = Infinity;
|
200
|
+
if(ts > timestamp) timestamp = ts;
|
201
|
+
});
|
202
|
+
return timestamp >= this.buildTimestamp;
|
203
|
+
};
|
204
|
+
|
205
|
+
NormalModule.prototype.size = function() {
|
206
|
+
return this._source ? this._source.size() : -1;
|
207
|
+
};
|
208
|
+
|
209
|
+
NormalModule.prototype.updateHash = function(hash) {
|
210
|
+
if(this._source) {
|
211
|
+
hash.update("source");
|
212
|
+
this._source.updateHash(hash);
|
213
|
+
} else
|
214
|
+
hash.update("null");
|
215
|
+
hash.update("meta");
|
216
|
+
hash.update(JSON.stringify(this.meta));
|
217
|
+
Module.prototype.updateHash.call(this, hash);
|
218
|
+
};
|
219
|
+
|
220
|
+
NormalModule.prototype.getSourceHash = function() {
|
221
|
+
if(!this._source) return "";
|
222
|
+
var hash = require("crypto").createHash("md5");
|
223
|
+
hash.update(this._source.source());
|
224
|
+
return hash.digest("hex");
|
225
|
+
};
|
226
|
+
|
227
|
+
NormalModule.prototype.getAllModuleDependencies = function() {
|
228
|
+
var list = [];
|
229
|
+
|
230
|
+
function doDep(dep) {
|
231
|
+
if(dep.module && list.indexOf(dep.module) < 0)
|
232
|
+
list.push(dep.module);
|
233
|
+
}
|
234
|
+
|
235
|
+
function doVariable(variable) {
|
236
|
+
variable.dependencies.forEach(doDep);
|
237
|
+
}
|
238
|
+
|
239
|
+
function doBlock(block) {
|
240
|
+
block.variables.forEach(doVariable);
|
241
|
+
block.dependencies.forEach(doDep);
|
242
|
+
block.blocks.forEach(doBlock);
|
243
|
+
}
|
244
|
+
doBlock(this);
|
245
|
+
return list;
|
246
|
+
};
|
247
|
+
|
248
|
+
NormalModule.prototype.createTemplate = function(keepModules, roots) {
|
249
|
+
roots.sort(function(a, b) {
|
250
|
+
var ia = a.identifier();
|
251
|
+
var ib = b.identifier();
|
252
|
+
if(ia < ib) return -1;
|
253
|
+
if(ib < ia) return 1;
|
254
|
+
return 0;
|
255
|
+
});
|
256
|
+
var template = new NormalModule("", "", "", [], "", null);
|
257
|
+
template._source = this._source;
|
258
|
+
template.built = this.built;
|
259
|
+
template.templateModules = keepModules;
|
260
|
+
template._templateOrigin = this;
|
261
|
+
template.readableIdentifier = function() {
|
262
|
+
return "template of " + this._templateOrigin.id + " referencing " + keepModules.map(function(m) {
|
263
|
+
return m.id;
|
264
|
+
}).join(", ");
|
265
|
+
};
|
266
|
+
template.identifier = function() {
|
267
|
+
var array = roots.map(function(m) {
|
268
|
+
return m.identifier();
|
269
|
+
});
|
270
|
+
array.sort();
|
271
|
+
return array.join("|");
|
272
|
+
};
|
273
|
+
var args = template.arguments = [];
|
274
|
+
|
275
|
+
function doDeps(deps) {
|
276
|
+
return deps.map(function(dep) {
|
277
|
+
if(dep.module && keepModules.indexOf(dep.module) < 0) {
|
278
|
+
var argName = "__webpack_module_template_argument_" + args.length + "__";
|
279
|
+
args.push(argName);
|
280
|
+
return new TemplateArgumentDependency(argName, dep);
|
281
|
+
} else {
|
282
|
+
return dep;
|
283
|
+
}
|
284
|
+
});
|
285
|
+
}
|
286
|
+
|
287
|
+
function doBlock(block, newBlock) {
|
288
|
+
block.variables.forEach(function(variable) {
|
289
|
+
var newDependencies = doDeps(variable.dependencies);
|
290
|
+
newBlock.addVariable(variable.name, variable.expression, newDependencies);
|
291
|
+
});
|
292
|
+
newBlock.dependencies = doDeps(block.dependencies);
|
293
|
+
block.blocks.forEach(function(childBlock) {
|
294
|
+
var newChildBlock = new AsyncDependenciesBlock(childBlock.name, childBlock.module, childBlock.loc);
|
295
|
+
newBlock.addBlock(newChildBlock);
|
296
|
+
doBlock(childBlock, newChildBlock);
|
297
|
+
});
|
298
|
+
}
|
299
|
+
doBlock(this, template);
|
300
|
+
return template;
|
301
|
+
};
|
302
|
+
|
303
|
+
NormalModule.prototype.getTemplateArguments = function(keepModules) {
|
304
|
+
var list = [];
|
305
|
+
|
306
|
+
function doDep(dep) {
|
307
|
+
if(dep.module && keepModules.indexOf(dep.module) < 0)
|
308
|
+
list.push(dep.module);
|
309
|
+
}
|
310
|
+
|
311
|
+
function doVariable(variable) {
|
312
|
+
variable.dependencies.forEach(doDep);
|
313
|
+
}
|
314
|
+
|
315
|
+
function doBlock(block) {
|
316
|
+
block.variables.forEach(doVariable);
|
317
|
+
block.dependencies.forEach(doDep);
|
318
|
+
block.blocks.forEach(doBlock);
|
319
|
+
}
|
320
|
+
doBlock(this);
|
321
|
+
return list;
|
322
|
+
};
|