Refactor webpack main
This commit is contained in:
parent
0d2faa0d0a
commit
9caaa664f7
|
@ -11,7 +11,16 @@ const ConcurrentCompilationError = require("./ConcurrentCompilationError");
|
||||||
const MultiStats = require("./MultiStats");
|
const MultiStats = require("./MultiStats");
|
||||||
const MultiWatching = require("./MultiWatching");
|
const MultiWatching = require("./MultiWatching");
|
||||||
|
|
||||||
|
/** @typedef {import("./Compiler")} Compiler */
|
||||||
|
|
||||||
|
const STATUS_PENDING = 0;
|
||||||
|
const STATUS_DONE = 1;
|
||||||
|
const STATUS_NEW = 2;
|
||||||
|
|
||||||
module.exports = class MultiCompiler {
|
module.exports = class MultiCompiler {
|
||||||
|
/**
|
||||||
|
* @param {Compiler[]} compilers child compilers
|
||||||
|
*/
|
||||||
constructor(compilers) {
|
constructor(compilers) {
|
||||||
this.hooks = Object.freeze({
|
this.hooks = Object.freeze({
|
||||||
done: new SyncHook(["stats"]),
|
done: new SyncHook(["stats"]),
|
||||||
|
@ -27,6 +36,8 @@ module.exports = class MultiCompiler {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.compilers = compilers;
|
this.compilers = compilers;
|
||||||
|
/** @type {WeakMap<Compiler, string[]>} */
|
||||||
|
this.dependencies = new WeakMap();
|
||||||
let doneCompilers = 0;
|
let doneCompilers = 0;
|
||||||
let compilerStats = [];
|
let compilerStats = [];
|
||||||
let index = 0;
|
let index = 0;
|
||||||
|
@ -90,6 +101,15 @@ module.exports = class MultiCompiler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the child compiler
|
||||||
|
* @param {string[]} dependencies its dependencies
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
setDependencies(compiler, dependencies) {
|
||||||
|
this.dependencies.set(compiler, dependencies);
|
||||||
|
}
|
||||||
|
|
||||||
validateDependencies(callback) {
|
validateDependencies(callback) {
|
||||||
const edges = new Set();
|
const edges = new Set();
|
||||||
const missing = [];
|
const missing = [];
|
||||||
|
@ -108,8 +128,9 @@ module.exports = class MultiCompiler {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
for (const source of this.compilers) {
|
for (const source of this.compilers) {
|
||||||
if (source.dependencies) {
|
const dependencies = this.dependencies.get(source);
|
||||||
for (const dep of source.dependencies) {
|
if (dependencies) {
|
||||||
|
for (const dep of dependencies) {
|
||||||
const target = this.compilers.find(c => c.name === dep);
|
const target = this.compilers.find(c => c.name === dep);
|
||||||
if (!target) {
|
if (!target) {
|
||||||
missing.push(dep);
|
missing.push(dep);
|
||||||
|
@ -160,8 +181,9 @@ module.exports = class MultiCompiler {
|
||||||
let list = remainingCompilers;
|
let list = remainingCompilers;
|
||||||
remainingCompilers = [];
|
remainingCompilers = [];
|
||||||
for (const c of list) {
|
for (const c of list) {
|
||||||
|
const dependencies = this.dependencies.get(c);
|
||||||
const ready =
|
const ready =
|
||||||
!c.dependencies || c.dependencies.every(isDependencyFulfilled);
|
!dependencies || dependencies.every(isDependencyFulfilled);
|
||||||
if (ready) {
|
if (ready) {
|
||||||
readyCompilers.push(c);
|
readyCompilers.push(c);
|
||||||
} else {
|
} else {
|
||||||
|
@ -188,11 +210,14 @@ module.exports = class MultiCompiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(watchOptions, handler) {
|
watch(watchOptions, handler) {
|
||||||
if (this.running) return handler(new ConcurrentCompilationError());
|
if (this.running) {
|
||||||
|
return handler(new ConcurrentCompilationError());
|
||||||
|
}
|
||||||
|
|
||||||
|
const watchings = [];
|
||||||
|
const allStats = this.compilers.map(() => null);
|
||||||
|
const compilerStatus = this.compilers.map(() => STATUS_PENDING);
|
||||||
|
|
||||||
let watchings = [];
|
|
||||||
let allStats = this.compilers.map(() => null);
|
|
||||||
let compilerStatus = this.compilers.map(() => false);
|
|
||||||
if (this.validateDependencies(handler)) {
|
if (this.validateDependencies(handler)) {
|
||||||
this.running = true;
|
this.running = true;
|
||||||
this.runWithDependencies(
|
this.runWithDependencies(
|
||||||
|
@ -208,12 +233,12 @@ module.exports = class MultiCompiler {
|
||||||
if (err) handler(err);
|
if (err) handler(err);
|
||||||
if (stats) {
|
if (stats) {
|
||||||
allStats[compilerIdx] = stats;
|
allStats[compilerIdx] = stats;
|
||||||
compilerStatus[compilerIdx] = "new";
|
compilerStatus[compilerIdx] = STATUS_NEW;
|
||||||
if (compilerStatus.every(Boolean)) {
|
if (compilerStatus.every(status => status !== STATUS_PENDING)) {
|
||||||
const freshStats = allStats.filter((s, idx) => {
|
const freshStats = allStats.filter((s, idx) => {
|
||||||
return compilerStatus[idx] === "new";
|
return compilerStatus[idx] === STATUS_NEW;
|
||||||
});
|
});
|
||||||
compilerStatus.fill(true);
|
compilerStatus.fill(STATUS_DONE);
|
||||||
const multiStats = new MultiStats(freshStats);
|
const multiStats = new MultiStats(freshStats);
|
||||||
handler(null, multiStats);
|
handler(null, multiStats);
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,9 +93,6 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
compiler.recordsOutputPath =
|
compiler.recordsOutputPath =
|
||||||
options.recordsOutputPath || options.recordsPath;
|
options.recordsOutputPath || options.recordsPath;
|
||||||
compiler.name = options.name;
|
compiler.name = options.name;
|
||||||
// TODO webpack 5 refactor this to MultiCompiler.setDependencies() with a WeakMap
|
|
||||||
// @ts-ignore TODO
|
|
||||||
compiler.dependencies = options.dependencies;
|
|
||||||
if (typeof options.target === "string") {
|
if (typeof options.target === "string") {
|
||||||
let JsonpTemplatePlugin;
|
let JsonpTemplatePlugin;
|
||||||
let FetchCompileWasmPlugin;
|
let FetchCompileWasmPlugin;
|
||||||
|
|
|
@ -0,0 +1,137 @@
|
||||||
|
/*
|
||||||
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||||
|
Author Tobias Koppers @sokra
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const util = require("util");
|
||||||
|
const { version } = require("../package.json");
|
||||||
|
const webpackOptionsSchema = require("../schemas/WebpackOptions.json");
|
||||||
|
const Compiler = require("./Compiler");
|
||||||
|
const MultiCompiler = require("./MultiCompiler");
|
||||||
|
const WebpackOptionsApply = require("./WebpackOptionsApply");
|
||||||
|
const WebpackOptionsDefaulter = require("./WebpackOptionsDefaulter");
|
||||||
|
const WebpackOptionsValidationError = require("./WebpackOptionsValidationError");
|
||||||
|
const NodeEnvironmentPlugin = require("./node/NodeEnvironmentPlugin");
|
||||||
|
const validateSchema = require("./validateSchema");
|
||||||
|
const webpack = require("./webpack");
|
||||||
|
|
||||||
|
exports = module.exports = webpack;
|
||||||
|
exports.WebpackOptionsApply = WebpackOptionsApply;
|
||||||
|
exports.WebpackOptionsDefaulter = WebpackOptionsDefaulter;
|
||||||
|
exports.WebpackOptionsValidationError = WebpackOptionsValidationError;
|
||||||
|
exports.Compiler = Compiler;
|
||||||
|
exports.MultiCompiler = MultiCompiler;
|
||||||
|
exports.NodeEnvironmentPlugin = NodeEnvironmentPlugin;
|
||||||
|
exports.validate = validateSchema.bind(null, webpackOptionsSchema);
|
||||||
|
exports.validateSchema = validateSchema;
|
||||||
|
exports.version = version;
|
||||||
|
|
||||||
|
const exportPlugins = (obj, mappings) => {
|
||||||
|
for (const name of Object.keys(mappings)) {
|
||||||
|
Object.defineProperty(obj, name, {
|
||||||
|
configurable: false,
|
||||||
|
enumerable: true,
|
||||||
|
get: mappings[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
exportPlugins(exports, {
|
||||||
|
AutomaticPrefetchPlugin: () => require("./AutomaticPrefetchPlugin"),
|
||||||
|
BannerPlugin: () => require("./BannerPlugin"),
|
||||||
|
ContextExclusionPlugin: () => require("./ContextExclusionPlugin"),
|
||||||
|
ContextReplacementPlugin: () => require("./ContextReplacementPlugin"),
|
||||||
|
DefinePlugin: () => require("./DefinePlugin"),
|
||||||
|
Dependency: () => require("./Dependency"),
|
||||||
|
DllPlugin: () => require("./DllPlugin"),
|
||||||
|
DllReferencePlugin: () => require("./DllReferencePlugin"),
|
||||||
|
EntryPlugin: () => require("./EntryPlugin"),
|
||||||
|
EnvironmentPlugin: () => require("./EnvironmentPlugin"),
|
||||||
|
EvalDevToolModulePlugin: () => require("./EvalDevToolModulePlugin"),
|
||||||
|
EvalSourceMapDevToolPlugin: () => require("./EvalSourceMapDevToolPlugin"),
|
||||||
|
ExternalsPlugin: () => require("./ExternalsPlugin"),
|
||||||
|
HotModuleReplacementPlugin: () => require("./HotModuleReplacementPlugin"),
|
||||||
|
IgnorePlugin: () => require("./IgnorePlugin"),
|
||||||
|
LibraryTemplatePlugin: () => require("./LibraryTemplatePlugin"),
|
||||||
|
LoaderOptionsPlugin: () => require("./LoaderOptionsPlugin"),
|
||||||
|
LoaderTargetPlugin: () => require("./LoaderTargetPlugin"),
|
||||||
|
MemoryOutputFileSystem: () => require("./MemoryOutputFileSystem"),
|
||||||
|
Module: () => require("./Module"),
|
||||||
|
ModuleFilenameHelpers: () => require("./ModuleFilenameHelpers"),
|
||||||
|
NoEmitOnErrorsPlugin: () => require("./NoEmitOnErrorsPlugin"),
|
||||||
|
NormalModuleReplacementPlugin: () =>
|
||||||
|
require("./NormalModuleReplacementPlugin"),
|
||||||
|
PrefetchPlugin: () => require("./PrefetchPlugin"),
|
||||||
|
ProgressPlugin: () => require("./ProgressPlugin"),
|
||||||
|
ProvidePlugin: () => require("./ProvidePlugin"),
|
||||||
|
SingleEntryPlugin: util.deprecate(
|
||||||
|
() => require("./EntryPlugin"),
|
||||||
|
"SingleEntryPlugin was renamed to EntryPlugin"
|
||||||
|
),
|
||||||
|
SetVarMainTemplatePlugin: () => require("./SetVarMainTemplatePlugin"),
|
||||||
|
SourceMapDevToolPlugin: () => require("./SourceMapDevToolPlugin"),
|
||||||
|
Stats: () => require("./Stats"),
|
||||||
|
Template: () => require("./Template"),
|
||||||
|
UmdMainTemplatePlugin: () => require("./UmdMainTemplatePlugin"),
|
||||||
|
WatchIgnorePlugin: () => require("./WatchIgnorePlugin")
|
||||||
|
});
|
||||||
|
|
||||||
|
exportPlugins((exports.cache = {}), {
|
||||||
|
MemoryCachePlugin: () => require("./cache/MemoryCachePlugin")
|
||||||
|
});
|
||||||
|
|
||||||
|
exportPlugins((exports.dependencies = {}), {
|
||||||
|
DependencyReference: () => require("./dependencies/DependencyReference")
|
||||||
|
});
|
||||||
|
|
||||||
|
exportPlugins((exports.ids = {}), {
|
||||||
|
ChunkModuleIdRangePlugin: () => require("./ids/ChunkModuleIdRangePlugin"),
|
||||||
|
NaturalModuleIdsPlugin: () => require("./ids/NaturalModuleIdsPlugin"),
|
||||||
|
OccurrenceModuleIdsPlugin: () => require("./ids/OccurrenceModuleIdsPlugin"),
|
||||||
|
NamedModuleIdsPlugin: () => require("./ids/NamedModuleIdsPlugin"),
|
||||||
|
DeterministicModuleIdsPlugin: () =>
|
||||||
|
require("./ids/DeterministicModuleIdsPlugin"),
|
||||||
|
NamedChunkIdsPlugin: () => require("./ids/NamedChunkIdsPlugin"),
|
||||||
|
OccurrenceChunkIdsPlugin: () => require("./ids/OccurrenceChunkIdsPlugin"),
|
||||||
|
HashedModuleIdsPlugin: () => require("./ids/HashedModuleIdsPlugin")
|
||||||
|
});
|
||||||
|
|
||||||
|
exportPlugins((exports.optimize = {}), {
|
||||||
|
AggressiveMergingPlugin: () => require("./optimize/AggressiveMergingPlugin"),
|
||||||
|
AggressiveSplittingPlugin: util.deprecate(
|
||||||
|
() => require("./optimize/AggressiveSplittingPlugin"),
|
||||||
|
"AggressiveSplittingPlugin is deprecated in favor of SplitChunksPlugin"
|
||||||
|
),
|
||||||
|
LimitChunkCountPlugin: () => require("./optimize/LimitChunkCountPlugin"),
|
||||||
|
MinChunkSizePlugin: () => require("./optimize/MinChunkSizePlugin"),
|
||||||
|
ModuleConcatenationPlugin: () =>
|
||||||
|
require("./optimize/ModuleConcatenationPlugin"),
|
||||||
|
RuntimeChunkPlugin: () => require("./optimize/RuntimeChunkPlugin"),
|
||||||
|
SideEffectsFlagPlugin: () => require("./optimize/SideEffectsFlagPlugin"),
|
||||||
|
SplitChunksPlugin: () => require("./optimize/SplitChunksPlugin")
|
||||||
|
});
|
||||||
|
|
||||||
|
exportPlugins((exports.web = {}), {
|
||||||
|
FetchCompileWasmPlugin: () => require("./web/FetchCompileWasmPlugin"),
|
||||||
|
JsonpTemplatePlugin: () => require("./web/JsonpTemplatePlugin")
|
||||||
|
});
|
||||||
|
|
||||||
|
exportPlugins((exports.webworker = {}), {
|
||||||
|
WebWorkerTemplatePlugin: () => require("./webworker/WebWorkerTemplatePlugin")
|
||||||
|
});
|
||||||
|
|
||||||
|
exportPlugins((exports.node = {}), {
|
||||||
|
NodeTemplatePlugin: () => require("./node/NodeTemplatePlugin"),
|
||||||
|
ReadFileCompileWasmPlugin: () => require("./node/ReadFileCompileWasmPlugin")
|
||||||
|
});
|
||||||
|
|
||||||
|
exportPlugins((exports.debug = {}), {
|
||||||
|
ProfilingPlugin: () => require("./debug/ProfilingPlugin")
|
||||||
|
});
|
||||||
|
|
||||||
|
exportPlugins((exports.util = {}), {
|
||||||
|
createHash: () => require("./util/createHash"),
|
||||||
|
comparators: () => require("./util/comparators")
|
||||||
|
});
|
236
lib/webpack.js
236
lib/webpack.js
|
@ -5,8 +5,6 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const util = require("util");
|
|
||||||
const version = require("../package.json").version;
|
|
||||||
const webpackOptionsSchema = require("../schemas/WebpackOptions.json");
|
const webpackOptionsSchema = require("../schemas/WebpackOptions.json");
|
||||||
const Compiler = require("./Compiler");
|
const Compiler = require("./Compiler");
|
||||||
const MultiCompiler = require("./MultiCompiler");
|
const MultiCompiler = require("./MultiCompiler");
|
||||||
|
@ -20,172 +18,88 @@ const validateSchema = require("./validateSchema");
|
||||||
/** @typedef {import("./Stats")} Stats */
|
/** @typedef {import("./Stats")} Stats */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {WebpackOptions} options options object
|
* @callback WebpackCallback
|
||||||
* @param {function(Error=, Stats=): void=} callback callback
|
* @param {Error=} err
|
||||||
* @returns {Compiler | MultiCompiler} the compiler object
|
* @param {Stats=} stats
|
||||||
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
const webpack = (options, callback) => {
|
|
||||||
const webpackOptionsValidationErrors = validateSchema(
|
|
||||||
webpackOptionsSchema,
|
|
||||||
options
|
|
||||||
);
|
|
||||||
if (webpackOptionsValidationErrors.length) {
|
|
||||||
throw new WebpackOptionsValidationError(webpackOptionsValidationErrors);
|
|
||||||
}
|
|
||||||
let compiler;
|
|
||||||
if (Array.isArray(options)) {
|
|
||||||
compiler = new MultiCompiler(options.map(options => webpack(options)));
|
|
||||||
} else if (typeof options === "object") {
|
|
||||||
options = new WebpackOptionsDefaulter().process(options);
|
|
||||||
|
|
||||||
compiler = new Compiler(options.context);
|
/**
|
||||||
compiler.options = options;
|
* @param {WebpackOptions[]} childOptions options array
|
||||||
new NodeEnvironmentPlugin().apply(compiler);
|
* @returns {MultiCompiler} a multi-compiler
|
||||||
if (options.plugins && Array.isArray(options.plugins)) {
|
*/
|
||||||
for (const plugin of options.plugins) {
|
const createMultiCompiler = childOptions => {
|
||||||
if (typeof plugin === "function") {
|
const compilers = childOptions.map(options => createCompiler(options));
|
||||||
plugin.call(compiler, compiler);
|
const compiler = new MultiCompiler(compilers);
|
||||||
} else {
|
for (const childCompiler of compilers) {
|
||||||
plugin.apply(compiler);
|
if (childCompiler.options.dependencies) {
|
||||||
}
|
compiler.setDependencies(
|
||||||
}
|
childCompiler,
|
||||||
|
childCompiler.options.dependencies
|
||||||
|
);
|
||||||
}
|
}
|
||||||
compiler.hooks.environment.call();
|
|
||||||
compiler.hooks.afterEnvironment.call();
|
|
||||||
compiler.options = new WebpackOptionsApply().process(options, compiler);
|
|
||||||
} else {
|
|
||||||
throw new Error("Invalid argument: options");
|
|
||||||
}
|
|
||||||
if (callback) {
|
|
||||||
if (typeof callback !== "function") {
|
|
||||||
throw new Error("Invalid argument: callback");
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
options.watch === true ||
|
|
||||||
(Array.isArray(options) && options.some(o => o.watch))
|
|
||||||
) {
|
|
||||||
const watchOptions = Array.isArray(options)
|
|
||||||
? options.map(o => o.watchOptions || {})
|
|
||||||
: options.watchOptions || {};
|
|
||||||
return compiler.watch(watchOptions, callback);
|
|
||||||
}
|
|
||||||
compiler.run((err, stats) => {
|
|
||||||
compiler.close(err2 => {
|
|
||||||
callback(err || err2, stats);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return compiler;
|
return compiler;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports = module.exports = webpack;
|
/**
|
||||||
exports.version = version;
|
* @param {WebpackOptions} options options object
|
||||||
|
* @returns {Compiler} a compiler
|
||||||
webpack.WebpackOptionsDefaulter = WebpackOptionsDefaulter;
|
*/
|
||||||
webpack.WebpackOptionsApply = WebpackOptionsApply;
|
const createCompiler = options => {
|
||||||
webpack.Compiler = Compiler;
|
options = new WebpackOptionsDefaulter().process(options);
|
||||||
webpack.MultiCompiler = MultiCompiler;
|
const compiler = new Compiler(options.context);
|
||||||
webpack.NodeEnvironmentPlugin = NodeEnvironmentPlugin;
|
compiler.options = options;
|
||||||
// @ts-ignore Global @this directive is not supported
|
new NodeEnvironmentPlugin().apply(compiler);
|
||||||
webpack.validate = validateSchema.bind(this, webpackOptionsSchema);
|
if (Array.isArray(options.plugins)) {
|
||||||
webpack.validateSchema = validateSchema;
|
for (const plugin of options.plugins) {
|
||||||
webpack.WebpackOptionsValidationError = WebpackOptionsValidationError;
|
if (typeof plugin === "function") {
|
||||||
|
plugin.call(compiler, compiler);
|
||||||
const exportPlugins = (obj, mappings) => {
|
} else {
|
||||||
for (const name of Object.keys(mappings)) {
|
plugin.apply(compiler);
|
||||||
Object.defineProperty(obj, name, {
|
}
|
||||||
configurable: false,
|
}
|
||||||
enumerable: true,
|
|
||||||
get: mappings[name]
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
compiler.hooks.environment.call();
|
||||||
|
compiler.hooks.afterEnvironment.call();
|
||||||
|
compiler.options = new WebpackOptionsApply().process(options, compiler);
|
||||||
|
return compiler;
|
||||||
};
|
};
|
||||||
|
|
||||||
exportPlugins(exports, {
|
/**
|
||||||
AutomaticPrefetchPlugin: () => require("./AutomaticPrefetchPlugin"),
|
* @param {WebpackOptions | WebpackOptions[]} options options object
|
||||||
BannerPlugin: () => require("./BannerPlugin"),
|
* @param {WebpackCallback=} callback callback
|
||||||
ContextExclusionPlugin: () => require("./ContextExclusionPlugin"),
|
* @returns {Compiler | MultiCompiler} the compiler object
|
||||||
ContextReplacementPlugin: () => require("./ContextReplacementPlugin"),
|
*/
|
||||||
DefinePlugin: () => require("./DefinePlugin"),
|
const webpack = (options, callback) => {
|
||||||
Dependency: () => require("./Dependency"),
|
const validationErrors = validateSchema(webpackOptionsSchema, options);
|
||||||
DllPlugin: () => require("./DllPlugin"),
|
if (validationErrors.length) {
|
||||||
DllReferencePlugin: () => require("./DllReferencePlugin"),
|
throw new WebpackOptionsValidationError(validationErrors);
|
||||||
EntryPlugin: () => require("./EntryPlugin"),
|
}
|
||||||
EnvironmentPlugin: () => require("./EnvironmentPlugin"),
|
let compiler;
|
||||||
EvalDevToolModulePlugin: () => require("./EvalDevToolModulePlugin"),
|
let watch = false;
|
||||||
EvalSourceMapDevToolPlugin: () => require("./EvalSourceMapDevToolPlugin"),
|
let watchOptions;
|
||||||
ExternalsPlugin: () => require("./ExternalsPlugin"),
|
if (Array.isArray(options)) {
|
||||||
HotModuleReplacementPlugin: () => require("./HotModuleReplacementPlugin"),
|
compiler = createMultiCompiler(options);
|
||||||
IgnorePlugin: () => require("./IgnorePlugin"),
|
watch = options.some(options => options.watch);
|
||||||
LibraryTemplatePlugin: () => require("./LibraryTemplatePlugin"),
|
watchOptions = options.map(options => options.watchOptions || {});
|
||||||
LoaderOptionsPlugin: () => require("./LoaderOptionsPlugin"),
|
} else {
|
||||||
LoaderTargetPlugin: () => require("./LoaderTargetPlugin"),
|
compiler = createCompiler(options);
|
||||||
MemoryOutputFileSystem: () => require("./MemoryOutputFileSystem"),
|
watch = options.watch;
|
||||||
Module: () => require("./Module"),
|
watchOptions = options.watchOptions || {};
|
||||||
ModuleFilenameHelpers: () => require("./ModuleFilenameHelpers"),
|
}
|
||||||
NoEmitOnErrorsPlugin: () => require("./NoEmitOnErrorsPlugin"),
|
if (callback) {
|
||||||
NormalModuleReplacementPlugin: () =>
|
if (watch) {
|
||||||
require("./NormalModuleReplacementPlugin"),
|
compiler.watch(watchOptions, callback);
|
||||||
PrefetchPlugin: () => require("./PrefetchPlugin"),
|
} else {
|
||||||
ProgressPlugin: () => require("./ProgressPlugin"),
|
compiler.run((err, stats) => {
|
||||||
ProvidePlugin: () => require("./ProvidePlugin"),
|
compiler.close(err2 => {
|
||||||
SingleEntryPlugin: util.deprecate(
|
callback(err || err2, stats);
|
||||||
() => require("./EntryPlugin"),
|
});
|
||||||
"SingleEntryPlugin was renamed to EntryPlugin"
|
});
|
||||||
),
|
}
|
||||||
SetVarMainTemplatePlugin: () => require("./SetVarMainTemplatePlugin"),
|
}
|
||||||
SourceMapDevToolPlugin: () => require("./SourceMapDevToolPlugin"),
|
return compiler;
|
||||||
Stats: () => require("./Stats"),
|
};
|
||||||
Template: () => require("./Template"),
|
|
||||||
UmdMainTemplatePlugin: () => require("./UmdMainTemplatePlugin"),
|
module.exports = webpack;
|
||||||
WatchIgnorePlugin: () => require("./WatchIgnorePlugin")
|
|
||||||
});
|
|
||||||
exportPlugins((exports.cache = {}), {
|
|
||||||
MemoryCachePlugin: () => require("./cache/MemoryCachePlugin")
|
|
||||||
});
|
|
||||||
exportPlugins((exports.dependencies = {}), {
|
|
||||||
DependencyReference: () => require("./dependencies/DependencyReference")
|
|
||||||
});
|
|
||||||
exportPlugins((exports.ids = {}), {
|
|
||||||
ChunkModuleIdRangePlugin: () => require("./ids/ChunkModuleIdRangePlugin"),
|
|
||||||
NaturalModuleIdsPlugin: () => require("./ids/NaturalModuleIdsPlugin"),
|
|
||||||
OccurrenceModuleIdsPlugin: () => require("./ids/OccurrenceModuleIdsPlugin"),
|
|
||||||
NamedModuleIdsPlugin: () => require("./ids/NamedModuleIdsPlugin"),
|
|
||||||
DeterministicModuleIdsPlugin: () =>
|
|
||||||
require("./ids/DeterministicModuleIdsPlugin"),
|
|
||||||
NamedChunkIdsPlugin: () => require("./ids/NamedChunkIdsPlugin"),
|
|
||||||
OccurrenceChunkIdsPlugin: () => require("./ids/OccurrenceChunkIdsPlugin"),
|
|
||||||
HashedModuleIdsPlugin: () => require("./ids/HashedModuleIdsPlugin")
|
|
||||||
});
|
|
||||||
exportPlugins((exports.optimize = {}), {
|
|
||||||
AggressiveMergingPlugin: () => require("./optimize/AggressiveMergingPlugin"),
|
|
||||||
AggressiveSplittingPlugin: util.deprecate(
|
|
||||||
() => require("./optimize/AggressiveSplittingPlugin"),
|
|
||||||
"AggressiveSplittingPlugin is deprecated in favor of SplitChunksPlugin"
|
|
||||||
),
|
|
||||||
LimitChunkCountPlugin: () => require("./optimize/LimitChunkCountPlugin"),
|
|
||||||
MinChunkSizePlugin: () => require("./optimize/MinChunkSizePlugin"),
|
|
||||||
ModuleConcatenationPlugin: () =>
|
|
||||||
require("./optimize/ModuleConcatenationPlugin"),
|
|
||||||
RuntimeChunkPlugin: () => require("./optimize/RuntimeChunkPlugin"),
|
|
||||||
SideEffectsFlagPlugin: () => require("./optimize/SideEffectsFlagPlugin"),
|
|
||||||
SplitChunksPlugin: () => require("./optimize/SplitChunksPlugin")
|
|
||||||
});
|
|
||||||
exportPlugins((exports.web = {}), {
|
|
||||||
FetchCompileWasmPlugin: () => require("./web/FetchCompileWasmPlugin"),
|
|
||||||
JsonpTemplatePlugin: () => require("./web/JsonpTemplatePlugin")
|
|
||||||
});
|
|
||||||
exportPlugins((exports.webworker = {}), {
|
|
||||||
WebWorkerTemplatePlugin: () => require("./webworker/WebWorkerTemplatePlugin")
|
|
||||||
});
|
|
||||||
exportPlugins((exports.node = {}), {
|
|
||||||
NodeTemplatePlugin: () => require("./node/NodeTemplatePlugin"),
|
|
||||||
ReadFileCompileWasmPlugin: () => require("./node/ReadFileCompileWasmPlugin")
|
|
||||||
});
|
|
||||||
exportPlugins((exports.debug = {}), {
|
|
||||||
ProfilingPlugin: () => require("./debug/ProfilingPlugin")
|
|
||||||
});
|
|
||||||
exportPlugins((exports.util = {}), {
|
|
||||||
createHash: () => require("./util/createHash"),
|
|
||||||
comparators: () => require("./util/comparators")
|
|
||||||
});
|
|
||||||
|
|
|
@ -84,7 +84,7 @@
|
||||||
"url": "https://github.com/webpack/webpack.git"
|
"url": "https://github.com/webpack/webpack.git"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/webpack/webpack",
|
"homepage": "https://github.com/webpack/webpack",
|
||||||
"main": "lib/webpack.js",
|
"main": "lib/index.js",
|
||||||
"bin": "./bin/webpack.js",
|
"bin": "./bin/webpack.js",
|
||||||
"files": [
|
"files": [
|
||||||
"lib/",
|
"lib/",
|
||||||
|
|
|
@ -77,7 +77,7 @@ describe("BenchmarkTestCases", function() {
|
||||||
|
|
||||||
function doLoadWebpack() {
|
function doLoadWebpack() {
|
||||||
const baselineWebpack = require.requireActual(
|
const baselineWebpack = require.requireActual(
|
||||||
path.resolve(baselinePath, "lib/webpack.js")
|
path.resolve(baselinePath, "lib/index.js")
|
||||||
);
|
);
|
||||||
baselines.push({
|
baselines.push({
|
||||||
name: baselineInfo.name,
|
name: baselineInfo.name,
|
||||||
|
|
|
@ -5,7 +5,7 @@ const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const rimraf = require("rimraf");
|
const rimraf = require("rimraf");
|
||||||
|
|
||||||
const webpack = require("../");
|
const webpack = require("..");
|
||||||
const WebpackOptionsDefaulter = require("../lib/WebpackOptionsDefaulter");
|
const WebpackOptionsDefaulter = require("../lib/WebpackOptionsDefaulter");
|
||||||
let fixtureCount = 0;
|
let fixtureCount = 0;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
const webpack = require("../");
|
const webpack = require("..");
|
||||||
const Stats = require("../lib/Stats");
|
const Stats = require("../lib/Stats");
|
||||||
const WebpackOptionsDefaulter = require("../lib/WebpackOptionsDefaulter");
|
const WebpackOptionsDefaulter = require("../lib/WebpackOptionsDefaulter");
|
||||||
const MemoryFs = require("memory-fs");
|
const MemoryFs = require("memory-fs");
|
||||||
|
|
|
@ -11,7 +11,7 @@ const createLazyTestEnv = require("./helpers/createLazyTestEnv");
|
||||||
const FakeDocument = require("./helpers/FakeDocument");
|
const FakeDocument = require("./helpers/FakeDocument");
|
||||||
|
|
||||||
const Stats = require("../lib/Stats");
|
const Stats = require("../lib/Stats");
|
||||||
const webpack = require("../lib/webpack");
|
const webpack = require("..");
|
||||||
const prepareOptions = require("./helpers/prepareOptions");
|
const prepareOptions = require("./helpers/prepareOptions");
|
||||||
|
|
||||||
describe("ConfigTestCases", () => {
|
describe("ConfigTestCases", () => {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
/*globals describe it */
|
/*globals describe it */
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
const webpack = require("../lib/webpack");
|
const webpack = require("..");
|
||||||
|
|
||||||
const base = path.join(__dirname, "fixtures", "errors");
|
const base = path.join(__dirname, "fixtures", "errors");
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
/* globals describe it */
|
/* globals describe it */
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const webpack = require("../");
|
const webpack = require("..");
|
||||||
|
|
||||||
describe("Examples", () => {
|
describe("Examples", () => {
|
||||||
const basePath = path.join(__dirname, "..", "examples");
|
const basePath = path.join(__dirname, "..", "examples");
|
||||||
|
|
|
@ -4,7 +4,7 @@ const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const mkdirp = require("mkdirp");
|
const mkdirp = require("mkdirp");
|
||||||
|
|
||||||
const webpack = require("../");
|
const webpack = require("..");
|
||||||
|
|
||||||
describe("HotModuleReplacementPlugin", () => {
|
describe("HotModuleReplacementPlugin", () => {
|
||||||
jest.setTimeout(20000);
|
jest.setTimeout(20000);
|
||||||
|
|
|
@ -7,7 +7,7 @@ const vm = require("vm");
|
||||||
const checkArrayExpectation = require("./checkArrayExpectation");
|
const checkArrayExpectation = require("./checkArrayExpectation");
|
||||||
const createLazyTestEnv = require("./helpers/createLazyTestEnv");
|
const createLazyTestEnv = require("./helpers/createLazyTestEnv");
|
||||||
|
|
||||||
const webpack = require("../lib/webpack");
|
const webpack = require("..");
|
||||||
|
|
||||||
const casesPath = path.join(__dirname, "hotCases");
|
const casesPath = path.join(__dirname, "hotCases");
|
||||||
let categories = fs
|
let categories = fs
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
/* globals describe it */
|
/* globals describe it */
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const MemoryFs = require("memory-fs");
|
const MemoryFs = require("memory-fs");
|
||||||
const webpack = require("../");
|
const webpack = require("..");
|
||||||
|
|
||||||
const createMultiCompiler = () => {
|
const createMultiCompiler = () => {
|
||||||
const compiler = webpack([
|
const compiler = webpack([
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const webpack = require("../lib/webpack");
|
const webpack = require("..");
|
||||||
|
|
||||||
describe("NodeTemplatePlugin", () => {
|
describe("NodeTemplatePlugin", () => {
|
||||||
jest.setTimeout(20000);
|
jest.setTimeout(20000);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const MemoryFs = require("memory-fs");
|
const MemoryFs = require("memory-fs");
|
||||||
const webpack = require("../");
|
const webpack = require("..");
|
||||||
|
|
||||||
const createMultiCompiler = () => {
|
const createMultiCompiler = () => {
|
||||||
const compiler = webpack([
|
const compiler = webpack([
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
/* globals describe it */
|
/* globals describe it */
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const MemoryFs = require("memory-fs");
|
const MemoryFs = require("memory-fs");
|
||||||
const webpack = require("../");
|
const webpack = require("..");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const rimraf = require("rimraf");
|
const rimraf = require("rimraf");
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*globals describe it */
|
/*globals describe it */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const webpack = require("../lib/webpack");
|
const webpack = require("..");
|
||||||
const MemoryFs = require("memory-fs");
|
const MemoryFs = require("memory-fs");
|
||||||
|
|
||||||
describe("Stats", () => {
|
describe("Stats", () => {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
const webpack = require("../lib/webpack");
|
const webpack = require("..");
|
||||||
const Stats = require("../lib/Stats");
|
const Stats = require("../lib/Stats");
|
||||||
|
|
||||||
const base = path.join(__dirname, "statsCases");
|
const base = path.join(__dirname, "statsCases");
|
||||||
|
|
|
@ -12,7 +12,7 @@ const createLazyTestEnv = require("./helpers/createLazyTestEnv");
|
||||||
|
|
||||||
const Stats = require("../lib/Stats");
|
const Stats = require("../lib/Stats");
|
||||||
const FileCachePlugin = require("../lib/cache/FileCachePlugin");
|
const FileCachePlugin = require("../lib/cache/FileCachePlugin");
|
||||||
const webpack = require("../lib/webpack");
|
const webpack = require("..");
|
||||||
|
|
||||||
const terserForTesting = new TerserPlugin({
|
const terserForTesting = new TerserPlugin({
|
||||||
cache: false,
|
cache: false,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const { describeCases } = require("./TestCases.template");
|
const { describeCases } = require("./TestCases.template");
|
||||||
const webpack = require("../lib/webpack");
|
const webpack = require("..");
|
||||||
|
|
||||||
describe("TestCases", () => {
|
describe("TestCases", () => {
|
||||||
describeCases({
|
describeCases({
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const { describeCases } = require("./TestCases.template");
|
const { describeCases } = require("./TestCases.template");
|
||||||
const webpack = require("../lib/webpack");
|
const webpack = require("..");
|
||||||
|
|
||||||
describe("TestCases", () => {
|
describe("TestCases", () => {
|
||||||
describeCases({
|
describeCases({
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const { describeCases } = require("./TestCases.template");
|
const { describeCases } = require("./TestCases.template");
|
||||||
const webpack = require("../lib/webpack");
|
const webpack = require("..");
|
||||||
|
|
||||||
describe("TestCases", () => {
|
describe("TestCases", () => {
|
||||||
describeCases({
|
describeCases({
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* globals describe, it */
|
/* globals describe, it */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const webpack = require("../lib/webpack");
|
const webpack = require("..");
|
||||||
|
|
||||||
describe("Validation", () => {
|
describe("Validation", () => {
|
||||||
const testCases = [
|
const testCases = [
|
||||||
|
|
|
@ -5,7 +5,7 @@ const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const MemoryFs = require("memory-fs");
|
const MemoryFs = require("memory-fs");
|
||||||
|
|
||||||
const webpack = require("../");
|
const webpack = require("..");
|
||||||
|
|
||||||
describe("WatchDetection", () => {
|
describe("WatchDetection", () => {
|
||||||
if (process.env.NO_WATCH_TESTS) {
|
if (process.env.NO_WATCH_TESTS) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ const createLazyTestEnv = require("./helpers/createLazyTestEnv");
|
||||||
const { remove } = require("./helpers/remove");
|
const { remove } = require("./helpers/remove");
|
||||||
|
|
||||||
const Stats = require("../lib/Stats");
|
const Stats = require("../lib/Stats");
|
||||||
const webpack = require("../lib/webpack");
|
const webpack = require("..");
|
||||||
|
|
||||||
function copyDiff(src, dest, initial) {
|
function copyDiff(src, dest, initial) {
|
||||||
if (!fs.existsSync(dest)) fs.mkdirSync(dest);
|
if (!fs.existsSync(dest)) fs.mkdirSync(dest);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
/* globals describe it */
|
/* globals describe it */
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const MemoryFs = require("memory-fs");
|
const MemoryFs = require("memory-fs");
|
||||||
const webpack = require("../");
|
const webpack = require("..");
|
||||||
|
|
||||||
const createCompiler = config => {
|
const createCompiler = config => {
|
||||||
const compiler = webpack(config);
|
const compiler = webpack(config);
|
||||||
|
|
Loading…
Reference in New Issue