function ExtractTextPlugin(options) { if(arguments.length > 1) { throw new Error("Breaking change: ExtractTextPlugin now only takes a single argument. Either an options " + "object *or* the name of the result file.\n" + "Example: if your old code looked like this:\n" + " new ExtractTextPlugin('css/[name].css', { disable: false, allChunks: true })\n\n" + "You would change it to:\n" + " new ExtractTextPlugin({ filename: 'css/[name].css', disable: false, allChunks: true })\n\n" + "The available options are:\n" + " filename: string\n" + " allChunks: boolean\n" + " disable: boolean\n"); } if(isString(options)) { options = { filename: options }; } else { schemaTester(pluginSchema, options); } this.filename = options.filename; this.id = options.id != null ? options.id : ++nextId; this.options = {}; mergeOptions(this.options, options); delete this.options.filename; delete this.options.id; }
n/a
function ExtractedModule(identifier, originalModule, source, sourceMap, addtitionalInformation, prevModules) { this._identifier = identifier; this._originalModule = originalModule; this._source = source; this._sourceMap = sourceMap; this._prevModules = prevModules; this.addtitionalInformation = addtitionalInformation; this.chunks = []; }
n/a
extract = function () { [native code] }
...
};
ExtractTextPlugin.prototype.extract = function(options) {
if(arguments.length > 1) {
throw new Error("Breaking change: extract now only takes a single argument. Either an options " +
"object *or* the loader(s).\n" +
"Example: if your old code looked like this:\n" +
" ExtractTextPlugin.extract('style-loader', 'css-loader
x27;)\n\n" +
"You would change it to:\n" +
" ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' })\n\n" +
"The available options are:\n" +
" use: string | object | loader[]\n" +
" fallback: string | object | loader[]\n" +
" publicPath: string\n");
}
...
function ExtractTextPlugin(options) { if(arguments.length > 1) { throw new Error("Breaking change: ExtractTextPlugin now only takes a single argument. Either an options " + "object *or* the name of the result file.\n" + "Example: if your old code looked like this:\n" + " new ExtractTextPlugin('css/[name].css', { disable: false, allChunks: true })\n\n" + "You would change it to:\n" + " new ExtractTextPlugin({ filename: 'css/[name].css', disable: false, allChunks: true })\n\n" + "The available options are:\n" + " filename: string\n" + " allChunks: boolean\n" + " disable: boolean\n"); } if(isString(options)) { options = { filename: options }; } else { schemaTester(pluginSchema, options); } this.filename = options.filename; this.id = options.id != null ? options.id : ++nextId; this.options = {}; mergeOptions(this.options, options); delete this.options.filename; delete this.options.id; }
n/a
loader = function (options) { return { loader: require.resolve("./loader"), options: options }; }
...
"}"
);
}
return source;
};
ExtractTextPlugin.prototype.loader = function(options) {
return ExtractTextPlugin.loader(mergeOptions({id: this.id}, options));
};
ExtractTextPlugin.prototype.extract = function(options) {
if(arguments.length > 1) {
throw new Error("Breaking change: extract now only takes a single argument. Either an options " +
"object *or* the loader(s).\n" +
"Example: if your old code looked like this:\n" +
...
function ExtractedModule(identifier, originalModule, source, sourceMap, addtitionalInformation, prevModules) { this._identifier = identifier; this._originalModule = originalModule; this._source = source; this._sourceMap = sourceMap; this._prevModules = prevModules; this.addtitionalInformation = addtitionalInformation; this.chunks = []; }
n/a
addChunk = function (chunk) { var idx = this.chunks.indexOf(chunk); if(idx < 0) this.chunks.push(chunk); }
...
if(c.isInitial()) return;
this.mergeNonInitialChunks(c, chunk, checkedChunks);
}, this);
} else if(checkedChunks.indexOf(chunk) < 0) {
checkedChunks.push(chunk);
chunk.modules.slice().forEach(function(module) {
intoChunk.addModule(module);
module.addChunk(intoChunk);
});
chunk.chunks.forEach(function(c) {
if(c.isInitial()) return;
this.mergeNonInitialChunks(c, intoChunk, checkedChunks);
}, this);
}
};
...
addPrevModules = function (prevModules) { prevModules.forEach(function(m) { if(this._prevModules.indexOf(m) < 0) this._prevModules.push(m); }, this); }
...
ExtractTextPluginCompilation.prototype.addModule = function(identifier, originalModule, source, additionalInformation, sourceMap
, prevModules) {
var m;
if(!this.modulesByIdentifier[identifier]) {
m = this.modulesByIdentifier[identifier] = new ExtractedModule(identifier, originalModule, source, sourceMap, additionalInformation
, prevModules);
} else {
m = this.modulesByIdentifier[identifier];
m.addPrevModules(prevModules);
if(originalModule.index2 < m.getOriginalModule().index2) {
m.setOriginalModule(originalModule);
}
}
return m;
};
...
getOrder = function () { // http://stackoverflow.com/a/14676665/1458162 return /^@import url/.test(this._source) ? 0 : 1; }
...
function isInvalidOrder(a, b) {
var bBeforeA = a.getPrevModules().indexOf(b) >= 0;
var aBeforeB = b.getPrevModules().indexOf(a) >= 0;
return aBeforeB && bBeforeA;
}
function getOrder(a, b) {
var aOrder = a.getOrder();
var bOrder = b.getOrder();
if(aOrder < bOrder) return -1;
if(aOrder > bOrder) return 1;
var aIndex = a.getOriginalModule().index2;
var bIndex = b.getOriginalModule().index2;
if(aIndex < bIndex) return -1;
if(aIndex > bIndex) return 1;
...
getOriginalModule = function () { return this._originalModule; }
...
ExtractTextPluginCompilation.prototype.addModule = function(identifier, originalModule, source, additionalInformation, sourceMap
, prevModules) {
var m;
if(!this.modulesByIdentifier[identifier]) {
m = this.modulesByIdentifier[identifier] = new ExtractedModule(identifier, originalModule, source, sourceMap, additionalInformation
, prevModules);
} else {
m = this.modulesByIdentifier[identifier];
m.addPrevModules(prevModules);
if(originalModule.index2 < m.getOriginalModule().index2) {
m.setOriginalModule(originalModule);
}
}
return m;
};
ExtractTextPluginCompilation.prototype.addResultToChunk = function(identifier, result, originalModule, extractedChunk) {
...
getPrevModules = function () { return this._prevModules; }
...
var moduleSource = module.source();
source.add(this.applyAdditionalInformation(moduleSource, module.additionalInformation));
}, this);
return source;
};
function isInvalidOrder(a, b) {
var bBeforeA = a.getPrevModules().indexOf(b) >= 0;
var aBeforeB = b.getPrevModules().indexOf(a) >= 0;
return aBeforeB && bBeforeA;
}
function getOrder(a, b) {
var aOrder = a.getOrder();
var bOrder = b.getOrder();
...
identifier = function () { return this._identifier; }
...
var bIndex = b.getOriginalModule().index2;
if(aIndex < bIndex) return -1;
if(aIndex > bIndex) return 1;
var bBeforeA = a.getPrevModules().indexOf(b) >= 0;
var aBeforeB = b.getPrevModules().indexOf(a) >= 0;
if(aBeforeB && !bBeforeA) return -1;
if(!aBeforeB && bBeforeA) return 1;
var ai = a.identifier();
var bi = b.identifier();
if(ai < bi) return -1;
if(ai > bi) return 1;
return 0;
}
function ExtractTextPlugin(options) {
...
removeChunk = function (chunk) { var idx = this.chunks.indexOf(chunk); if(idx >= 0) { this.chunks.splice(idx, 1); chunk.removeModule(this); return true; } return false; }
n/a
rewriteChunkInReasons = function (oldChunk, newChunks) { }
n/a
setOriginalModule = function (originalModule) { this._originalModule = originalModule; }
...
var m;
if(!this.modulesByIdentifier[identifier]) {
m = this.modulesByIdentifier[identifier] = new ExtractedModule(identifier, originalModule, source, sourceMap, additionalInformation
, prevModules);
} else {
m = this.modulesByIdentifier[identifier];
m.addPrevModules(prevModules);
if(originalModule.index2 < m.getOriginalModule().index2) {
m.setOriginalModule(originalModule);
}
}
return m;
};
ExtractTextPluginCompilation.prototype.addResultToChunk = function(identifier, result, originalModule, extractedChunk) {
if(!Array.isArray(result)) {
...
source = function () { if(this._sourceMap) return new SourceMapSource(this._source, null, this._sourceMap); else return new RawSource(this._source); }
...
prevModules.push(module);
}, this);
};
ExtractTextPlugin.prototype.renderExtractedChunk = function(chunk) {
var source = new ConcatSource();
chunk.modules.forEach(function(module) {
var moduleSource = module.source();
source.add(this.applyAdditionalInformation(moduleSource, module.additionalInformation));
}, this);
return source;
};
function isInvalidOrder(a, b) {
var bBeforeA = a.getPrevModules().indexOf(b) >= 0;
...
function ExtractTextPlugin(options) { if(arguments.length > 1) { throw new Error("Breaking change: ExtractTextPlugin now only takes a single argument. Either an options " + "object *or* the name of the result file.\n" + "Example: if your old code looked like this:\n" + " new ExtractTextPlugin('css/[name].css', { disable: false, allChunks: true })\n\n" + "You would change it to:\n" + " new ExtractTextPlugin({ filename: 'css/[name].css', disable: false, allChunks: true })\n\n" + "The available options are:\n" + " filename: string\n" + " allChunks: boolean\n" + " disable: boolean\n"); } if(isString(options)) { options = { filename: options }; } else { schemaTester(pluginSchema, options); } this.filename = options.filename; this.id = options.id != null ? options.id : ++nextId; this.options = {}; mergeOptions(this.options, options); delete this.options.filename; delete this.options.id; }
n/a
extract = function () { [native code] }
...
};
ExtractTextPlugin.prototype.extract = function(options) {
if(arguments.length > 1) {
throw new Error("Breaking change: extract now only takes a single argument. Either an options " +
"object *or* the loader(s).\n" +
"Example: if your old code looked like this:\n" +
" ExtractTextPlugin.extract('style-loader', 'css-loader
x27;)\n\n" +
"You would change it to:\n" +
" ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' })\n\n" +
"The available options are:\n" +
" use: string | object | loader[]\n" +
" fallback: string | object | loader[]\n" +
" publicPath: string\n");
}
...
loader = function (options) { return { loader: require.resolve("./loader"), options: options }; }
...
"}"
);
}
return source;
};
ExtractTextPlugin.prototype.loader = function(options) {
return ExtractTextPlugin.loader(mergeOptions({id: this.id}, options));
};
ExtractTextPlugin.prototype.extract = function(options) {
if(arguments.length > 1) {
throw new Error("Breaking change: extract now only takes a single argument. Either an options " +
"object *or* the loader(s).\n" +
"Example: if your old code looked like this:\n" +
...
apply = function (compiler) { var options = this.options; compiler.plugin("this-compilation", function(compilation) { var extractCompilation = new ExtractTextPluginCompilation(); compilation.plugin("normal-module-loader", function(loaderContext, module) { loaderContext[NS] = function(content, opt) { if(options.disable) return false; if(!Array.isArray(content) && content != null) throw new Error("Exported value was not extracted as an array: " + JSON.stringify(content)); module[NS] = { content: content, options: opt || {} }; return options.allChunks || module[NS + "/extract"]; // eslint-disable-line no-path-concat }; }); var filename = this.filename; var id = this.id; var extractedChunks, entryChunks, initialChunks; compilation.plugin("optimize-tree", function(chunks, modules, callback) { extractedChunks = chunks.map(function() { return new Chunk(); }); chunks.forEach(function(chunk, i) { var extractedChunk = extractedChunks[i]; extractedChunk.index = i; extractedChunk.originalChunk = chunk; extractedChunk.name = chunk.name; extractedChunk.entrypoints = chunk.entrypoints; chunk.chunks.forEach(function(c) { extractedChunk.addChunk(extractedChunks[chunks.indexOf(c)]); }); chunk.parents.forEach(function(c) { extractedChunk.addParent(extractedChunks[chunks.indexOf(c)]); }); }); async.forEach(chunks, function(chunk, callback) { var extractedChunk = extractedChunks[chunks.indexOf(chunk)]; var shouldExtract = !!(options.allChunks || chunk.isInitial()); async.forEach(chunk.modules.slice(), function(module, callback) { var meta = module[NS]; if(meta && (!meta.options.id || meta.options.id === id)) { var wasExtracted = Array.isArray(meta.content); if(shouldExtract !== wasExtracted) { module[NS + "/extract"] = shouldExtract; // eslint-disable-line no-path-concat compilation.rebuildModule(module, function(err) { if(err) { compilation.errors.push(err); return callback(); } meta = module[NS]; if(!Array.isArray(meta.content)) { err = new Error(module.identifier() + " doesn't export content"); compilation.errors.push(err); return callback(); } if(meta.content) extractCompilation.addResultToChunk(module.identifier(), meta.content, module, extractedChunk); callback(); }); } else { if(meta.content) extractCompilation.addResultToChunk(module.identifier(), meta.content, module, extractedChunk); callback(); } } else callback(); }, function(err) { if(err) return callback(err); callback(); }); }, function(err) { if(err) return callback(err); extractedChunks.forEach(function(extractedChunk) { if(extractedChunk.isInitial()) this.mergeNonInitialChunks(extractedChunk); }, this); extractedChunks.forEach(function(extractedChunk) { if(!extractedChunk.isInitial()) { extractedChunk.modules.slice().forEach(function(module) { extractedChunk.removeModule(module); }); } }); compilation.applyPlugins("optimize-extracted-chunks", extractedChunks); callback(); }.bind(this)); }.bind(this)); compilation.plugin("additional-assets", function(callback) { extractedChunks.forEach(function(extractedChunk) { if(extractedChunk.modules.length) { extractedChunk.modules.sort(function(a, b) { if(!options.ignoreOrder && isInvalidOrder(a, b)) { compilation.errors.push(new OrderUndefinedError(a.getOriginalModule())); compilation.errors.push(new OrderUndefinedError(b.getOriginalModule())); } return getOrder(a, b); }); var chunk = extractedChunk.originalChunk; var source = this.renderExtractedChunk(extractedChunk); var getPath = (format) => compilation.getPath(format, { chunk: chunk }).replace(/\[(?:(\w+):)?contenthash(?::([a-z]+\d*))?(?::(\d+))?\]/ig, function() { return loaderUtils.getHa ...
...
var childFilename = "extract-text-webpack-plugin-output-filename"; // eslint-disable-line no-path-concat
var publicPath = typeof query.publicPath === "string" ? query.publicPath : this._compilation.outputOptions.publicPath
;
var outputOptions = {
filename: childFilename,
publicPath: publicPath
};
var childCompiler = this._compilation.createChildCompiler("extract-text-webpack-plugin", outputOptions);
childCompiler.apply(new NodeTemplatePlugin(outputOptions));
childCompiler.apply(new LibraryTemplatePlugin(null, "commonjs2"));
childCompiler.apply(new NodeTargetPlugin());
childCompiler.apply(new SingleEntryPlugin(this.context, "!!" + request));
childCompiler.apply(new LimitChunkCountPlugin({ maxChunks: 1 }));
var subCache = "subcache " + NS + " " + request; // eslint-disable-line no-path-concat
childCompiler.plugin("compilation", function(compilation) {
if(compilation.cache) {
...
applyAdditionalInformation = function (source, info) { if(info) { return new ConcatSource( "@media " + info[0] + " {", source, "}" ); } return source; }
...
}, this);
};
ExtractTextPlugin.prototype.renderExtractedChunk = function(chunk) {
var source = new ConcatSource();
chunk.modules.forEach(function(module) {
var moduleSource = module.source();
source.add(this.applyAdditionalInformation(moduleSource, module.additionalInformation
));
}, this);
return source;
};
function isInvalidOrder(a, b) {
var bBeforeA = a.getPrevModules().indexOf(b) >= 0;
var aBeforeB = b.getPrevModules().indexOf(a) >= 0;
...
extract = function (options) { if(arguments.length > 1) { throw new Error("Breaking change: extract now only takes a single argument. Either an options " + "object *or* the loader(s).\n" + "Example: if your old code looked like this:\n" + " ExtractTextPlugin.extract('style-loader', 'css-loader')\n\n" + "You would change it to:\n" + " ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' })\n\n" + "The available options are:\n" + " use: string | object | loader[]\n" + " fallback: string | object | loader[]\n" + " publicPath: string\n"); } if(options.fallbackLoader) { console.warn('fallbackLoader option has been deprecated - replace with "fallback"'); } if(options.loader) { console.warn('loader option has been deprecated - replace with "use"'); } if(Array.isArray(options) || isString(options) || typeof options.options === "object" || typeof options.query === 'object') { options = { loader: options }; } else { schemaTester(loaderSchema, options); } var loader = options.use || options.loader; var before = options.fallback || options.fallbackLoader || []; if(isString(loader)) { loader = loader.split("!"); } if(isString(before)) { before = before.split("!"); } else if(!Array.isArray(before)) { before = [before]; } options = mergeOptions({omit: before.length, remove: true}, options); delete options.loader; delete options.use; delete options.fallback; delete options.fallbackLoader; return [this.loader(options)] .concat(before, loader) .map(getLoaderObject); }
...
};
ExtractTextPlugin.prototype.extract = function(options) {
if(arguments.length > 1) {
throw new Error("Breaking change: extract now only takes a single argument. Either an options " +
"object *or* the loader(s).\n" +
"Example: if your old code looked like this:\n" +
" ExtractTextPlugin.extract('style-loader', 'css-loader
x27;)\n\n" +
"You would change it to:\n" +
" ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' })\n\n" +
"The available options are:\n" +
" use: string | object | loader[]\n" +
" fallback: string | object | loader[]\n" +
" publicPath: string\n");
}
...
loader = function (options) { return ExtractTextPlugin.loader(mergeOptions({id: this.id}, options)); }
...
"}"
);
}
return source;
};
ExtractTextPlugin.prototype.loader = function(options) {
return ExtractTextPlugin.loader(mergeOptions({id: this.id}, options));
};
ExtractTextPlugin.prototype.extract = function(options) {
if(arguments.length > 1) {
throw new Error("Breaking change: extract now only takes a single argument. Either an options " +
"object *or* the loader(s).\n" +
"Example: if your old code looked like this:\n" +
...
mergeNonInitialChunks = function (chunk, intoChunk, checkedChunks) { if(!intoChunk) { checkedChunks = []; chunk.chunks.forEach(function(c) { if(c.isInitial()) return; this.mergeNonInitialChunks(c, chunk, checkedChunks); }, this); } else if(checkedChunks.indexOf(chunk) < 0) { checkedChunks.push(chunk); chunk.modules.slice().forEach(function(module) { intoChunk.addModule(module); module.addChunk(intoChunk); }); chunk.chunks.forEach(function(c) { if(c.isInitial()) return; this.mergeNonInitialChunks(c, intoChunk, checkedChunks); }, this); } }
...
}
ExtractTextPlugin.prototype.mergeNonInitialChunks = function(chunk, intoChunk, checkedChunks) {
if(!intoChunk) {
checkedChunks = [];
chunk.chunks.forEach(function(c) {
if(c.isInitial()) return;
this.mergeNonInitialChunks(c, chunk, checkedChunks);
}, this);
} else if(checkedChunks.indexOf(chunk) < 0) {
checkedChunks.push(chunk);
chunk.modules.slice().forEach(function(module) {
intoChunk.addModule(module);
module.addChunk(intoChunk);
});
...
renderExtractedChunk = function (chunk) { var source = new ConcatSource(); chunk.modules.forEach(function(module) { var moduleSource = module.source(); source.add(this.applyAdditionalInformation(moduleSource, module.additionalInformation)); }, this); return source; }
...
if(!options.ignoreOrder && isInvalidOrder(a, b)) {
compilation.errors.push(new OrderUndefinedError(a.getOriginalModule()));
compilation.errors.push(new OrderUndefinedError(b.getOriginalModule()));
}
return getOrder(a, b);
});
var chunk = extractedChunk.originalChunk;
var source = this.renderExtractedChunk(extractedChunk);
var getPath = (format) => compilation.getPath(format, {
chunk: chunk
}).replace(/\[(?:(\w+):)?contenthash(?::([a-z]+\d*))?(?::(\d+))?\]/ig, function() {
return loaderUtils.getHashDigest(source.source(), arguments[1], arguments[2], parseInt(arguments[3], 10));
});
...
loader = function (source) { if(this.cacheable) this.cacheable(); return source; }
...
"}"
);
}
return source;
};
ExtractTextPlugin.prototype.loader = function(options) {
return ExtractTextPlugin.loader(mergeOptions({id: this.id}, options));
};
ExtractTextPlugin.prototype.extract = function(options) {
if(arguments.length > 1) {
throw new Error("Breaking change: extract now only takes a single argument. Either an options " +
"object *or* the loader(s).\n" +
"Example: if your old code looked like this:\n" +
...
pitch = function (request) { if(this.cacheable) this.cacheable(); var query = loaderUtils.getOptions(this) || {}; var loaders = this.loaders.slice(this.loaderIndex + 1); this.addDependency(this.resourcePath); // We already in child compiler, return empty bundle if(this[NS] === undefined) { throw new Error( '"extract-text-webpack-plugin" loader is used without the corresponding plugin, ' + 'refer to https://github.com/webpack/extract-text-webpack-plugin for the usage example' ); } else if(this[NS] === false) { return ""; } else if(this[NS](null, query)) { if(query.omit) { this.loaderIndex += +query.omit + 1; request = request.split("!").slice(+query.omit).join("!"); loaders = loaders.slice(+query.omit); } var resultSource; if(query.remove) { resultSource = "// removed by extract-text-webpack-plugin"; } else { resultSource = undefined; } var childFilename = "extract-text-webpack-plugin-output-filename"; // eslint-disable-line no-path-concat var publicPath = typeof query.publicPath === "string" ? query.publicPath : this._compilation.outputOptions.publicPath; var outputOptions = { filename: childFilename, publicPath: publicPath }; var childCompiler = this._compilation.createChildCompiler("extract-text-webpack-plugin", outputOptions); childCompiler.apply(new NodeTemplatePlugin(outputOptions)); childCompiler.apply(new LibraryTemplatePlugin(null, "commonjs2")); childCompiler.apply(new NodeTargetPlugin()); childCompiler.apply(new SingleEntryPlugin(this.context, "!!" + request)); childCompiler.apply(new LimitChunkCountPlugin({ maxChunks: 1 })); var subCache = "subcache " + NS + " " + request; // eslint-disable-line no-path-concat childCompiler.plugin("compilation", function(compilation) { if(compilation.cache) { if(!compilation.cache[subCache]) compilation.cache[subCache] = {}; compilation.cache = compilation.cache[subCache]; } }); // We set loaderContext[NS] = false to indicate we already in // a child compiler so we don't spawn another child compilers from there. childCompiler.plugin("this-compilation", function(compilation) { compilation.plugin("normal-module-loader", function(loaderContext, module) { loaderContext[NS] = false; if (module.request === request) { module.loaders = loaders.map(function(loader) { return { loader: loader.path, options: loader.options }; }); } }); }); var source; childCompiler.plugin("after-compile", function(compilation, callback) { source = compilation.assets[childFilename] && compilation.assets[childFilename].source(); // Remove all chunk assets compilation.chunks.forEach(function(chunk) { chunk.files.forEach(function(file) { delete compilation.assets[file]; }); }); callback(); }); var callback = this.async(); childCompiler.runAsChild(function(err, entries, compilation) { if(err) return callback(err); if(compilation.errors.length > 0) { return callback(compilation.errors[0]); } compilation.fileDependencies.forEach(function(dep) { this.addDependency(dep); }, this); compilation.contextDependencies.forEach(function(dep) { this.addContextDependency(dep); }, this); if(!source) { return callback(new Error("Didn't get a result from child compiler")); } try { var text = this.exec(source, request); if(typeof text === "string") text = [[0, text]]; text.forEach(function(item) { var id = item[0]; compilation.modules.forEach(function(module) { if(module.id === id) item[0] = module.identifier(); }); }); this[NS](text, query); if(text.locals && typeof resultSource !== "undefined") { resultSource += "\nmodule.exports = " + JSON.stringify(text.locals) + ";"; } } catch(e) { return callback(e); } if(resultSource) callback(null, resultSource); else callback(); }.bind(this)); } }
n/a