Merge branch 'master' into bump_prettier

This commit is contained in:
Tobias Koppers 2018-03-29 11:48:02 +02:00
commit 8d8da4cdff
44 changed files with 482 additions and 129 deletions

View File

@ -52,7 +52,7 @@ yarn add webpack --dev
<h2 align="center">Introduction</h2>
> This README reflects Webpack v2.x and v3.x. The Webpack v1.x documentation has been deprecated and deleted.
> This README reflects webpack v2.x and v3.x. The webpack v1.x documentation has been deprecated and deleted.
webpack is a bundler for modules. The main purpose is to bundle JavaScript
files for usage in a browser, yet it is also capable of transforming, bundling,

79
bin/webpack.js Normal file → Executable file
View File

@ -1,21 +1,80 @@
#!/usr/bin/env node
function runCommand(command, options) {
const cp = require("child_process");
return new Promise((resolve, reject) => {
const executedCommand = cp.spawn(command, options, {
stdio: "inherit"
});
executedCommand.on("error", error => {
reject(error);
});
executedCommand.on("exit", code => {
if (code === 0) {
resolve(true);
} else {
reject();
}
});
});
}
let webpackCliInstalled = false;
try {
require.resolve("webpack-cli");
webpackCliInstalled = true;
} catch (e) {
} catch (err) {
webpackCliInstalled = false;
}
if (webpackCliInstalled) {
require("webpack-cli"); // eslint-disable-line node/no-missing-require, node/no-extraneous-require, node/no-unpublished-require
if (!webpackCliInstalled) {
const path = require("path");
const fs = require("fs");
const readLine = require("readline");
const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock"));
const packageManager = isYarn ? "yarn" : "npm";
const options = ["install", "-D", "webpack-cli"];
if (isYarn) {
options[0] = "add";
}
const commandToBeRun = `${packageManager} ${options.join(" ")}`;
const question = `Would you like to install webpack-cli? (That will run ${commandToBeRun}) `;
console.error("The CLI moved into a separate package: webpack-cli");
const questionInterface = readLine.createInterface({
input: process.stdin,
output: process.stdout
});
questionInterface.question(question, answer => {
questionInterface.close();
switch (answer.toLowerCase()) {
case "y":
case "yes":
case "1": {
runCommand(packageManager, options)
.then(result => {
return require("webpack-cli"); //eslint-disable-line
})
.catch(error => {
console.error(error);
process.exitCode = 1;
});
break;
}
default: {
console.error(
"It needs to be installed alongside webpack to use the CLI"
);
process.exitCode = 1;
break;
}
}
});
} else {
console.error("The CLI moved into a separate package: webpack-cli.");
console.error(
"Please install 'webpack-cli' in addition to webpack itself to use the CLI."
);
console.error("-> When using npm: npm install webpack-cli -D");
console.error("-> When using yarn: yarn add webpack-cli -D");
process.exitCode = 1;
require("webpack-cli"); // eslint-disable-line
}

View File

@ -158,8 +158,6 @@ class Compilation extends Tapable {
beforeChunkAssets: new SyncHook([]),
additionalChunkAssets: new SyncHook(["chunks"]),
records: new SyncHook(["compilation", "records"]),
additionalAssets: new AsyncSeriesHook([]),
optimizeChunkAssets: new AsyncSeriesHook(["chunks"]),
afterOptimizeChunkAssets: new SyncHook(["chunks"]),
@ -253,6 +251,9 @@ class Compilation extends Tapable {
this.childrenCounters = {};
this.usedChunkIds = null;
this.usedModuleIds = null;
this.fileTimestamps = undefined;
this.contextTimestamps = undefined;
this.compilationDependencies = undefined;
this._buildingModules = new Map();
this._rebuildingModules = new Map();
@ -277,6 +278,9 @@ class Compilation extends Tapable {
if (this.cache && this.cache[cacheName]) {
const cacheModule = this.cache[cacheName];
if (typeof cacheModule.updateCacheModule === "function")
cacheModule.updateCacheModule(module);
let rebuild = true;
if (this.fileTimestamps && this.contextTimestamps) {
rebuild = cacheModule.needRebuild(

View File

@ -94,36 +94,36 @@ class Compiler extends Tapable {
this.resolverFactory.plugin("resolver normal", resolver => {
resolver.plugin(hook, fn);
});
}, "webpack: Using compiler.resolvers.normal is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver normal", resolver => {\n resolver.plugin(/* ... */);\n}); instead.'),
}, "webpack: Using compiler.resolvers.normal is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver normal", resolver => {\n resolver.plugin(/* */);\n}); instead.'),
apply: util.deprecate((...args) => {
this.resolverFactory.plugin("resolver normal", resolver => {
resolver.apply(...args);
});
}, "webpack: Using compiler.resolvers.normal is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver normal", resolver => {\n resolver.apply(/* ... */);\n}); instead.')
}, "webpack: Using compiler.resolvers.normal is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver normal", resolver => {\n resolver.apply(/* */);\n}); instead.')
},
loader: {
plugins: util.deprecate((hook, fn) => {
this.resolverFactory.plugin("resolver loader", resolver => {
resolver.plugin(hook, fn);
});
}, "webpack: Using compiler.resolvers.loader is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver loader", resolver => {\n resolver.plugin(/* ... */);\n}); instead.'),
}, "webpack: Using compiler.resolvers.loader is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver loader", resolver => {\n resolver.plugin(/* */);\n}); instead.'),
apply: util.deprecate((...args) => {
this.resolverFactory.plugin("resolver loader", resolver => {
resolver.apply(...args);
});
}, "webpack: Using compiler.resolvers.loader is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver loader", resolver => {\n resolver.apply(/* ... */);\n}); instead.')
}, "webpack: Using compiler.resolvers.loader is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver loader", resolver => {\n resolver.apply(/* */);\n}); instead.')
},
context: {
plugins: util.deprecate((hook, fn) => {
this.resolverFactory.plugin("resolver context", resolver => {
resolver.plugin(hook, fn);
});
}, "webpack: Using compiler.resolvers.context is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver context", resolver => {\n resolver.plugin(/* ... */);\n}); instead.'),
}, "webpack: Using compiler.resolvers.context is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver context", resolver => {\n resolver.plugin(/* */);\n}); instead.'),
apply: util.deprecate((...args) => {
this.resolverFactory.plugin("resolver context", resolver => {
resolver.apply(...args);
});
}, "webpack: Using compiler.resolvers.context is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver context", resolver => {\n resolver.apply(/* ... */);\n}); instead.')
}, "webpack: Using compiler.resolvers.context is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver context", resolver => {\n resolver.apply(/* */);\n}); instead.')
}
};
@ -448,10 +448,7 @@ class Compiler extends Tapable {
}
createContextModuleFactory() {
const contextModuleFactory = new ContextModuleFactory(
this.resolverFactory,
this.inputFileSystem
);
const contextModuleFactory = new ContextModuleFactory(this.resolverFactory);
this.hooks.contextModuleFactory.call(contextModuleFactory);
return contextModuleFactory;
}

View File

@ -43,6 +43,14 @@ class ContextModule extends Module {
if (typeof options.mode !== "string")
throw new Error("options.mode is a required option");
this._identifier = this._createIdentifier();
}
updateCacheModule(module) {
this.resolveDependencies = module.resolveDependencies;
this.options = module.options;
this.resolveOptions = module.resolveOptions;
}
prettyRegExp(regexString) {
@ -63,7 +71,7 @@ class ContextModule extends Module {
.join("!");
}
identifier() {
_createIdentifier() {
let identifier = this.context;
if (this.options.resourceQuery)
identifier += ` ${this.options.resourceQuery}`;
@ -80,6 +88,10 @@ class ContextModule extends Module {
return identifier;
}
identifier() {
return this._identifier;
}
readableIdentifier(requestShortener) {
let identifier = requestShortener.shorten(this.context);
if (this.options.resourceQuery)

View File

@ -10,6 +10,7 @@ class Dependency {
this.module = null;
this.weak = false;
this.optional = false;
this.loc = undefined;
}
getResourceIdentifier() {

View File

@ -47,7 +47,7 @@ module.exports = class HotUpdateChunkTemplate extends Tapable {
hotUpdateChunk.removedModules = removedModules;
const modulesSource = Template.renderChunkModules(
hotUpdateChunk,
() => true,
m => typeof m.source === "function",
moduleTemplate,
dependencyTemplates
);

View File

@ -83,9 +83,9 @@ class JavascriptGenerator {
* we can not inject "foo" twice, therefore we just make two IIFEs like so:
* (function(foo, bar, baz){
* (function(foo, some, more){
* ...
* }(...));
* }(...));
*
* }());
* }());
*
* "splitVariablesInUniqueNamedChunks" splits the variables shown above up to this:
* [[foo, bar, baz], [foo, some, more]]
@ -177,8 +177,8 @@ class JavascriptGenerator {
/*
* creates the start part of a IIFE around the module to inject a variable name
* (function(...){ <- this part
* }.call(...))
* (function(){ <- this part
* }.call())
*/
variableInjectionFunctionWrapperStartCode(varNames) {
const args = varNames.join(", ");
@ -194,8 +194,8 @@ class JavascriptGenerator {
/*
* creates the end part of a IIFE around the module to inject a variable name
* (function(...){
* }.call(...)) <- this part
* (function(){
* }.call()) <- this part
*/
variableInjectionFunctionWrapperEndCode(module, varExpressions, block) {
const firstParam = this.contextArgument(module, block);

View File

@ -32,18 +32,18 @@ class JavascriptModulesPlugin {
});
normalModuleFactory.hooks.createGenerator
.for("javascript/auto")
.tap("JavascriptModulesPlugin", options => {
return new JavascriptGenerator(options);
.tap("JavascriptModulesPlugin", () => {
return new JavascriptGenerator();
});
normalModuleFactory.hooks.createGenerator
.for("javascript/dynamic")
.tap("JavascriptModulesPlugin", options => {
return new JavascriptGenerator(options);
.tap("JavascriptModulesPlugin", () => {
return new JavascriptGenerator();
});
normalModuleFactory.hooks.createGenerator
.for("javascript/esm")
.tap("JavascriptModulesPlugin", options => {
return new JavascriptGenerator(options);
.tap("JavascriptModulesPlugin", () => {
return new JavascriptGenerator();
});
compilation.mainTemplate.hooks.renderManifest.tap(
"JavascriptModulesPlugin",

View File

@ -67,6 +67,8 @@ class Module extends DependenciesBlock {
// delayed operations
this._rewriteChunkInReasons = undefined;
this.useSourceMap = false;
}
get exportsArgument() {
@ -336,5 +338,6 @@ Module.prototype.build = null;
Module.prototype.source = null;
Module.prototype.size = null;
Module.prototype.nameForCondition = null;
Module.prototype.updateCacheModule = null;
module.exports = Module;

View File

@ -15,10 +15,13 @@ class MultiModule extends Module {
// Info from Factory
this.dependencies = dependencies;
this.name = name;
this._identifier = `multi ${this.dependencies
.map(d => d.request)
.join(" ")}`;
}
identifier() {
return `multi ${this.dependencies.map(d => d.request).join(" ")}`;
return this._identifier;
}
readableIdentifier(requestShortener) {

View File

@ -13,8 +13,10 @@ module.exports = class NoModeWarning extends WebpackError {
this.name = "NoModeWarning";
this.message =
"configuration\n" +
"The 'mode' option has not been set. " +
"Set 'mode' option to 'development' or 'production' to enable defaults for this environment. ";
"The 'mode' option has not been set, webpack will fallback to 'production' for this value. " +
"Set 'mode' option to 'development' or 'production' to enable defaults for each environment.\n" +
"You can also set it to 'none' to disable any default behavior. " +
"Learn more: https://webpack.js.org/concepts/mode/";
Error.captureStackTrace(this, this.constructor);
}

View File

@ -122,6 +122,15 @@ class NormalModule extends Module {
return this.resource;
}
updateCacheModule(module) {
this.userRequest = module.userRequest;
this.parser = module.parser;
this.generator = module.generator;
this.resource = module.resource;
this.loaders = module.loaders;
this.resolveOptions = module.resolveOptions;
}
createSourceForAsset(name, content, sourceMap) {
if (!sourceMap) {
return new RawSource(content);

View File

@ -43,18 +43,12 @@ class OptionsDefaulter {
setProperty(
options,
name,
this.defaults[name].call(this, getProperty(options, name), options),
options
this.defaults[name].call(this, getProperty(options, name), options)
);
break;
case "make":
if (getProperty(options, name) === undefined)
setProperty(
options,
name,
this.defaults[name].call(this, options),
options
);
setProperty(options, name, this.defaults[name].call(this, options));
break;
case "append": {
let oldValue = getProperty(options, name);

View File

@ -1178,7 +1178,11 @@ class Parser extends Tapable {
walkExportDefaultDeclaration(statement) {
this.hooks.export.call(statement);
if (statement.declaration.id) {
if (
statement.declaration.id &&
statement.declaration.type !== "FunctionExpression" &&
statement.declaration.type !== "ClassExpression"
) {
if (
!this.hooks.exportDeclaration.call(statement, statement.declaration)
) {
@ -1647,7 +1651,7 @@ class Parser extends Tapable {
expression.arguments &&
expression.arguments.length > 0
) {
// (function(...) { }.call/bind(?, ...))
// (function(…) { }.call/bind(?, …))
walkIIFE.call(
this,
expression.callee.object,
@ -1658,7 +1662,7 @@ class Parser extends Tapable {
expression.callee.type === "FunctionExpression" &&
expression.arguments
) {
// (function(...) { }(...))
// (function(…) { }(…))
walkIIFE.call(this, expression.callee, expression.arguments);
} else if (expression.callee.type === "Import") {
result = this.hooks.importCall.call(expression);

View File

@ -24,7 +24,7 @@ const createDefaultHandler = profile => {
for (let detail of details) {
if (!detail) continue;
if (detail.length > 40) {
detail = `...${detail.substr(detail.length - 37)}`;
detail = `${detail.substr(detail.length - 39)}`;
}
msg += ` ${detail}`;
}

View File

@ -19,6 +19,8 @@ class Stats {
constructor(compilation) {
this.compilation = compilation;
this.hash = compilation.hash;
this.startTime = undefined;
this.endTime = undefined;
}
static filterWarnings(warnings, warningsFilter) {

View File

@ -118,7 +118,7 @@ module.exports = class Template {
if (minId > module.id) minId = module.id;
}
if (minId < 16 + ("" + minId).length) {
// add minId x ',' instead of 'Array(minId).concat(...)'
// add minId x ',' instead of 'Array(minId).concat()'
minId = 0;
}
var objectOverhead = modules

View File

@ -34,11 +34,7 @@ class WebAssemblyParser extends Tapable {
module
).map(exp => exp.name);
for (const imp of WebAssembly.Module.imports(module)) {
const dep = new WebAssemblyImportDependency(
imp.module,
imp.name,
imp.kind
);
const dep = new WebAssemblyImportDependency(imp.module, imp.name);
state.module.addDependency(dep);
}
})

View File

@ -91,14 +91,16 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
this.set("output.filename", "[name].js");
this.set("output.chunkFilename", "make", options => {
const filename = options.output.filename;
if (typeof filename === "function") return filename;
const hasName = filename.includes("[name]");
const hasId = filename.includes("[id]");
const hasChunkHash = filename.includes("[chunkhash]");
// Anything changing depending on chunk is fine
if (hasChunkHash || hasName || hasId) return filename;
// Elsewise prefix "[id]." in front of the basename to make it changing
return filename.replace(/(^|\/)([^/]*(?:\?|$))/, "$1[id].$2");
if (typeof filename !== "function") {
const hasName = filename.includes("[name]");
const hasId = filename.includes("[id]");
const hasChunkHash = filename.includes("[chunkhash]");
// Anything changing depending on chunk is fine
if (hasChunkHash || hasName || hasId) return filename;
// Elsewise prefix "[id]." in front of the basename to make it changing
return filename.replace(/(^|\/)([^/]*(?:\?|$))/, "$1[id].$2");
}
return "[id].js";
});
this.set("output.webassemblyModuleFilename", "[modulehash].module.wasm");
this.set("output.library", "");

View File

@ -116,7 +116,7 @@ class WebpackOptionsValidationError extends WebpackError {
if (!required.includes(property)) return property + "?";
return property;
})
.concat(schema.additionalProperties ? ["..."] : [])
.concat(schema.additionalProperties ? [""] : [])
.join(", ")} }`;
}
if (schema.additionalProperties) {
@ -175,7 +175,7 @@ class WebpackOptionsValidationError extends WebpackError {
" new webpack.LoaderOptionsPlugin({\n" +
" // test: /\\.xxx$/, // may apply this only for some modules\n" +
" options: {\n" +
` ${err.params.additionalProperty}: ...\n` +
` ${err.params.additionalProperty}: \n` +
" }\n" +
" })\n" +
" ]"

View File

@ -152,10 +152,10 @@ class AMDDefineDependencyParserPlugin {
switch (expr.arguments.length) {
case 1:
if (isCallable(expr.arguments[0])) {
// define(f() {...})
// define(f() {})
fn = expr.arguments[0];
} else if (expr.arguments[0].type === "ObjectExpression") {
// define({...})
// define({})
obj = expr.arguments[0];
} else {
// define(expr)
@ -166,45 +166,45 @@ class AMDDefineDependencyParserPlugin {
case 2:
if (expr.arguments[0].type === "Literal") {
namedModule = expr.arguments[0].value;
// define("...", ...)
// define("…", …)
if (isCallable(expr.arguments[1])) {
// define("...", f() {...})
// define("…", f() {…})
fn = expr.arguments[1];
} else if (expr.arguments[1].type === "ObjectExpression") {
// define("...", {...})
// define("…", {…})
obj = expr.arguments[1];
} else {
// define("...", expr)
// define("", expr)
// unclear if function or object
obj = fn = expr.arguments[1];
}
} else {
array = expr.arguments[0];
if (isCallable(expr.arguments[1])) {
// define([...], f() {})
// define([], f() {})
fn = expr.arguments[1];
} else if (expr.arguments[1].type === "ObjectExpression") {
// define([...], {...})
// define([…], {…})
obj = expr.arguments[1];
} else {
// define([...], expr)
// define([], expr)
// unclear if function or object
obj = fn = expr.arguments[1];
}
}
break;
case 3:
// define("...", [...], f() {...})
// define("…", […], f() {…})
namedModule = expr.arguments[0].value;
array = expr.arguments[1];
if (isCallable(expr.arguments[2])) {
// define("...", [...], f() {})
// define("…", […], f() {})
fn = expr.arguments[2];
} else if (expr.arguments[2].type === "ObjectExpression") {
// define("...", [...], {...})
// define("…", […], {…})
obj = expr.arguments[2];
} else {
// define("...", [...], expr)
// define("…", […], expr)
// unclear if function or object
obj = fn = expr.arguments[2];
}

View File

@ -216,7 +216,7 @@ class AMDRequireDependenciesBlockParserPlugin {
parser.state.module.errors.push(
new UnsupportedFeatureWarning(
parser.state.module,
"Cannot statically analyse 'require(..., ...)' in line " +
"Cannot statically analyse 'require(…, …)' in line " +
expr.loc.start.line
)
);

View File

@ -550,8 +550,7 @@ class ConcatenatedModule extends Module {
HarmonyExportExpressionDependency,
new HarmonyExportExpressionDependencyConcatenatedTemplate(
dependencyTemplates.get(HarmonyExportExpressionDependency),
this.rootModule,
moduleToInfoMap
this.rootModule
)
);
innerDependencyTemplates.set(

View File

@ -85,7 +85,9 @@ module.exports = class SplitChunksPlugin {
static normalizeOptions(options = {}) {
return {
chunks: options.chunks || "all",
chunksFilter: SplitChunksPlugin.normalizeChunksFilter(
options.chunks || "all"
),
minSize: options.minSize || 0,
minChunks: options.minChunks || 1,
maxAsyncRequests: options.maxAsyncRequests || 1,
@ -135,6 +137,19 @@ module.exports = class SplitChunksPlugin {
if (typeof name === "function") return name;
}
static normalizeChunksFilter(chunks) {
if (chunks === "initial") {
return chunk => chunk.canBeInitial();
}
if (chunks === "async") {
return chunk => !chunk.canBeInitial();
}
if (chunks === "all") {
return () => true;
}
if (typeof chunks === "function") return chunks;
}
static normalizeCacheGroups({ cacheGroups, automaticNameDelimiter }) {
if (typeof cacheGroups === "function") {
return cacheGroups;
@ -162,6 +177,11 @@ module.exports = class SplitChunksPlugin {
r
);
if (result.name) result.getName = () => result.name;
if (result.chunks) {
result.chunksFilter = SplitChunksPlugin.normalizeChunksFilter(
result.chunks
);
}
results.push(result);
}
}
@ -174,7 +194,9 @@ module.exports = class SplitChunksPlugin {
name: option.name,
automaticNameDelimiter
}),
chunks: option.chunks,
chunksFilter: SplitChunksPlugin.normalizeChunksFilter(
option.chunks
),
enforce: option.enforce,
minSize: option.minSize,
minChunks: option.minChunks,
@ -264,7 +286,8 @@ module.exports = class SplitChunksPlugin {
const cacheGroup = {
key: cacheGroupSource.key,
priority: cacheGroupSource.priority || 0,
chunks: cacheGroupSource.chunks || this.options.chunks,
chunksFilter:
cacheGroupSource.chunksFilter || this.options.chunksFilter,
minSize:
cacheGroupSource.minSize !== undefined
? cacheGroupSource.minSize
@ -304,16 +327,9 @@ module.exports = class SplitChunksPlugin {
// Break if minimum number of chunks is not reached
if (chunkIndices.length < cacheGroup.minChunks) continue;
// Select chunks by configuration
const selectedChunks =
cacheGroup.chunks === "initial"
? Array.from(chunkCombination).filter(chunk =>
chunk.canBeInitial()
)
: cacheGroup.chunks === "async"
? Array.from(chunkCombination).filter(
chunk => !chunk.canBeInitial()
)
: Array.from(chunkCombination);
const selectedChunks = Array.from(chunkCombination).filter(
cacheGroup.chunksFilter
);
// Break if minimum number of chunks is not reached
if (selectedChunks.length < cacheGroup.minChunks) continue;
// Determine name for split chunk

View File

@ -53,7 +53,7 @@ module.exports = class SizeLimitsPlugin {
for (const pair of compilation.entrypoints) {
const name = pair[0];
const entry = pair[1];
const size = getEntrypointSize(entry, compilation);
const size = getEntrypointSize(entry);
if (size > entrypointSizeLimit) {
entrypointsOverLimit.push({

View File

@ -1,6 +1,6 @@
{
"name": "webpack",
"version": "4.2.0",
"version": "4.3.0",
"author": "Tobias Koppers @sokra",
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
"license": "MIT",

View File

@ -324,14 +324,7 @@
},
"chunkFilename": {
"description": "The filename of non-entry chunks as relative path inside the `output.path` directory.",
"anyOf": [
{
"type": "string"
},
{
"instanceof": "Function"
}
],
"type": "string",
"absolutePath": false
},
"webassemblyModuleFilename": {
@ -1337,10 +1330,17 @@
"properties": {
"chunks": {
"description": "Select chunks for determining shared modules (defaults to \"async\", \"initial\" and \"all\" requires adding these chunks to the HTML)",
"enum": [
"initial",
"async",
"all"
"oneOf": [
{
"enum": [
"initial",
"async",
"all"
]
},
{
"instanceof": "Function"
}
]
},
"minSize": {
@ -1427,10 +1427,17 @@
},
"chunks": {
"description": "Select chunks for determining cache group content (defaults to \"initial\", \"initial\" and \"all\" requires adding these chunks to the HTML)",
"enum": [
"initial",
"async",
"all"
"oneOf": [
{
"enum": [
"initial",
"async",
"all"
]
},
{
"instanceof": "Function"
}
]
},
"enforce": {

View File

@ -210,7 +210,7 @@ describe("Validation", () => {
" new webpack.LoaderOptionsPlugin({",
" // test: /\\.xxx$/, // may apply this only for some modules",
" options: {",
" postcss: ...",
" postcss: ",
" }",
" })",
" ]"
@ -297,7 +297,7 @@ describe("Validation", () => {
},
message: [
" - configuration.plugins[0] should be one of these:",
" object { apply, ... } | function",
" object { apply, } | function",
" -> Plugin of type object or instanceof Function",
" Details:",
" * configuration.plugins[0] should be an object.",
@ -314,7 +314,7 @@ describe("Validation", () => {
},
message: [
" - configuration.plugins[0] should be one of these:",
" object { apply, ... } | function",
" object { apply, } | function",
" -> Plugin of type object or instanceof Function",
" Details:",
" * configuration.plugins[0] should be an object.",
@ -331,7 +331,7 @@ describe("Validation", () => {
},
message: [
" - configuration.plugins[0] should be one of these:",
" object { apply, ... } | function",
" object { apply, } | function",
" -> Plugin of type object or instanceof Function",
" Details:",
" * configuration.plugins[0] should be an object.",
@ -348,7 +348,7 @@ describe("Validation", () => {
},
message: [
" - configuration.plugins[0] should be one of these:",
" object { apply, ... } | function",
" object { apply, } | function",
" -> Plugin of type object or instanceof Function",
" Details:",
" * configuration.plugins[0] should be an object.",
@ -365,7 +365,7 @@ describe("Validation", () => {
},
message: [
" - configuration.plugins[0] should be one of these:",
" object { apply, ... } | function",
" object { apply, } | function",
" -> Plugin of type object or instanceof Function",
" Details:",
" * configuration.plugins[0] misses the property 'apply'.",

View File

@ -23,7 +23,7 @@ function join(a, b) {
return a;
}
console.log("compile scripts...");
console.log("compile scripts");
var extraArgsNoWatch = extraArgs.slice(0);
var watchIndex = extraArgsNoWatch.indexOf("--watch");

View File

@ -11,8 +11,8 @@ function testCase(number) {
}
it("should parse complex require calls", function() {
should.strictEqual(new(require("./constructor"))(1234).value, 1234, "Parse require in new(...) should work");
should.strictEqual(new ( require ( "./constructor" ) ) ( 1234 ) .value, 1234, "Parse require in new(...) should work, with spaces");
should.strictEqual(new(require("./constructor"))(1234).value, 1234, "Parse require in new() should work");
should.strictEqual(new ( require ( "./constructor" ) ) ( 1234 ) .value, 1234, "Parse require in new() should work, with spaces");
});
it("should let the user hide the require function", function() {

View File

@ -1,5 +1,5 @@
if(module.hot) {
it("should run module.hot.accept(...)", function() {
it("should run module.hot.accept()", function() {
module.hot.accept("./a", function() {});
});
it("should run module.hot.accept()", function() {

View File

@ -0,0 +1 @@
export default function() {}

View File

@ -0,0 +1 @@
export default (function() {})

View File

@ -0,0 +1 @@
export default function foo() {}

View File

@ -0,0 +1 @@
export default (function bar() {})

View File

@ -0,0 +1 @@
export default class {}

View File

@ -0,0 +1 @@
export default (class {})

View File

@ -0,0 +1 @@
export default class A {}

View File

@ -0,0 +1 @@
export default (class A {})

View File

@ -0,0 +1,57 @@
it("should compile default export unnamed function declaration", function() {
return import(/* webpackChunkName: "a" */ "./a")
.then(({ default: a }) => {
a()
});
});
it("should compile default export unnamed function expression", function() {
return import(/* webpackChunkName: "b" */ "./b")
.then(({ default: b }) => {
b()
});
});
it("should compile default export named function declaration", function() {
return import(/* webpackChunkName: "c" */ "./c")
.then(({ default: c }) => {
c()
});
});
it("should compile default export named function expression", function() {
return import(/* webpackChunkName: "d" */ "./d")
.then(({ default: d }) => {
d()
});
});
it("should compile default export unnamed class declaration", function() {
return import(/* webpackChunkName: "e" */ "./e")
.then(({ default: E }) => {
new E()
});
});
it("should compile default export unnamed class expression", function() {
return import(/* webpackChunkName: "f" */ "./f")
.then(({ default: F }) => {
new F()
});
});
it("should compile default export named class declaration", function() {
return import(/* webpackChunkName: "g" */ "./g")
.then(({ default: G }) => {
new G()
});
});
it("should compile default export named class expression", function() {
return import(/* webpackChunkName: "h" */ "./h")
.then(({ default: H }) => {
new H()
});
});

View File

@ -1,4 +1,4 @@
Hash: 885948e5541fff6e85ac
Hash: 550499db0a071b393308
Time: Xms
Built at: Thu Jan 01 1970 00:00:00 GMT
Asset Size Chunks Chunk Names
@ -8,7 +8,8 @@ Entrypoint main = bundle.js
[0] ./index.js 0 bytes {0} [built]
WARNING in configuration
The 'mode' option has not been set. Set 'mode' option to 'development' or 'production' to enable defaults for this environment.
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/
Child child:
Asset Size Chunks Chunk Names
child.js 2.61 KiB 0 child

View File

@ -257,4 +257,129 @@ Child name-too-long:
> ./c cccccccccccccccccccccccccccccc
[0] ./d.js 20 bytes {1} {10} {11} {12} [built]
[1] ./f.js 20 bytes {2} {11} {12} [built]
[5] ./c.js 72 bytes {7} {12} [built]
[5] ./c.js 72 bytes {7} {12} [built]
Child custom-chunks-filter:
Entrypoint main = default/main.js
Entrypoint a = default/a.js
Entrypoint b = default/vendors~async-a~async-b~async-c~b~c.js default/vendors~async-a~async-b~b.js default/b.js
Entrypoint c = default/vendors~async-a~async-b~async-c~b~c.js default/vendors~async-c~c.js default/c.js
chunk {0} default/vendors~async-a~async-b~async-c~b~c.js (vendors~async-a~async-b~async-c~b~c) 20 bytes <{9}> ={1}= ={11}= ={12}= ={2}= ={3}= ={4}= ={6}= ={7}= ={8}= >{2}< >{5}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors~async-a~async-b~async-c~b~c)
> ./b b
> ./c c
> ./a [8] ./index.js 1:0-47
> ./b [8] ./index.js 2:0-47
> ./c [8] ./index.js 3:0-47
[2] ./node_modules/x.js 20 bytes {0} {10} [built]
chunk {1} default/async-a~async-b~async-c~b~c.js (async-a~async-b~async-c~b~c) 20 bytes <{9}> ={0}= ={2}= ={3}= ={4}= ={6}= ={7}= ={8}= >{2}< >{5}< [rendered] split chunk (cache group: default) (name: async-a~async-b~async-c~b~c)
> ./a [8] ./index.js 1:0-47
> ./b [8] ./index.js 2:0-47
> ./c [8] ./index.js 3:0-47
[0] ./d.js 20 bytes {1} {10} {11} {12} [built]
chunk {2} default/async-b~async-c~async-g~b~c.js (async-b~async-c~async-g~b~c) 20 bytes <{0}> <{1}> <{10}> <{3}> <{6}> <{9}> ={0}= ={1}= ={3}= ={4}= ={5}= ={7}= ={8}= [rendered] split chunk (cache group: default) (name: async-b~async-c~async-g~b~c)
> ./g [] 6:0-47
> ./g [] 6:0-47
> ./b [8] ./index.js 2:0-47
> ./c [8] ./index.js 3:0-47
[1] ./f.js 20 bytes {2} {11} {12} [built]
chunk {3} default/vendors~async-a~async-b~b.js (vendors~async-a~async-b~b) 20 bytes <{9}> ={0}= ={1}= ={11}= ={2}= ={6}= ={7}= >{2}< >{5}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors~async-a~async-b~b)
> ./b b
> ./a [8] ./index.js 1:0-47
> ./b [8] ./index.js 2:0-47
[3] ./node_modules/y.js 20 bytes {3} {10} [built]
chunk {4} default/vendors~async-c~c.js (vendors~async-c~c) 20 bytes <{9}> ={0}= ={1}= ={12}= ={2}= ={8}= [initial] [rendered] split chunk (cache group: vendors) (name: vendors~async-c~c)
> ./c c
> ./c [8] ./index.js 3:0-47
[7] ./node_modules/z.js 20 bytes {4} [built]
chunk {5} default/async-g.js (async-g) 34 bytes <{0}> <{1}> <{10}> <{3}> <{6}> ={2}= [rendered]
> ./g [] 6:0-47
> ./g [] 6:0-47
[9] ./g.js 34 bytes {5} [built]
chunk {6} default/async-a.js (async-a) 156 bytes <{9}> ={0}= ={1}= ={3}= >{2}< >{5}< [rendered]
> ./a [8] ./index.js 1:0-47
[6] ./a.js + 1 modules 156 bytes {6} {10} [built]
| ./a.js 121 bytes [built]
| ./e.js 20 bytes [built]
chunk {7} default/async-b.js (async-b) 72 bytes <{9}> ={0}= ={1}= ={2}= ={3}= [rendered]
> ./b [8] ./index.js 2:0-47
[4] ./b.js 72 bytes {7} {11} [built]
chunk {8} default/async-c.js (async-c) 72 bytes <{9}> ={0}= ={1}= ={2}= ={4}= [rendered]
> ./c [8] ./index.js 3:0-47
[5] ./c.js 72 bytes {8} {12} [built]
chunk {9} default/main.js (main) 147 bytes >{0}< >{1}< >{2}< >{3}< >{4}< >{6}< >{7}< >{8}< [entry] [rendered]
> ./ main
[8] ./index.js 147 bytes {9} [built]
chunk {10} default/a.js (a) 216 bytes >{2}< >{5}< [entry] [rendered]
> ./a a
[0] ./d.js 20 bytes {1} {10} {11} {12} [built]
[2] ./node_modules/x.js 20 bytes {0} {10} [built]
[3] ./node_modules/y.js 20 bytes {3} {10} [built]
[6] ./a.js + 1 modules 156 bytes {6} {10} [built]
| ./a.js 121 bytes [built]
| ./e.js 20 bytes [built]
chunk {11} default/b.js (b) 112 bytes ={0}= ={3}= [entry] [rendered]
> ./b b
[0] ./d.js 20 bytes {1} {10} {11} {12} [built]
[1] ./f.js 20 bytes {2} {11} {12} [built]
[4] ./b.js 72 bytes {7} {11} [built]
chunk {12} default/c.js (c) 112 bytes ={0}= ={4}= [entry] [rendered]
> ./c c
[0] ./d.js 20 bytes {1} {10} {11} {12} [built]
[1] ./f.js 20 bytes {2} {11} {12} [built]
[5] ./c.js 72 bytes {8} {12} [built]
Child custom-chunks-filter-in-cache-groups:
Entrypoint main = default/main.js
Entrypoint a = default/a.js
Entrypoint b = default/vendors.js default/b.js
Entrypoint c = default/vendors.js default/c.js
chunk {0} default/vendors.js (vendors) 112 bytes <{5}> ={2}= ={3}= ={4}= ={7}= ={8}= >{1}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors)
> ./b b
> ./c c
> ./a [8] ./index.js 1:0-47
> ./b [8] ./index.js 2:0-47
> ./c [8] ./index.js 3:0-47
[2] ./node_modules/x.js 20 bytes {0} {6} [built]
[3] ./node_modules/y.js 20 bytes {0} {6} [built]
[6] ./node_modules/z.js 20 bytes {0} [built]
[10] multi x y z 52 bytes {0} [built]
chunk {1} default/async-g.js (async-g) 54 bytes <{0}> <{2}> <{6}> [rendered]
> ./g [] 6:0-47
> ./g [] 6:0-47
[1] ./f.js 20 bytes {1} {3} {4} {7} {8} [built]
[9] ./g.js 34 bytes {1} [built]
chunk {2} default/async-a.js (async-a) 176 bytes <{5}> ={0}= >{1}< [rendered]
> ./a [8] ./index.js 1:0-47
[0] ./d.js 20 bytes {2} {3} {4} {6} {7} {8} [built]
[7] ./a.js + 1 modules 156 bytes {2} {6} [built]
| ./a.js 121 bytes [built]
| ./e.js 20 bytes [built]
chunk {3} default/async-b.js (async-b) 112 bytes <{5}> ={0}= [rendered]
> ./b [8] ./index.js 2:0-47
[0] ./d.js 20 bytes {2} {3} {4} {6} {7} {8} [built]
[1] ./f.js 20 bytes {1} {3} {4} {7} {8} [built]
[4] ./b.js 72 bytes {3} {7} [built]
chunk {4} default/async-c.js (async-c) 112 bytes <{5}> ={0}= [rendered]
> ./c [8] ./index.js 3:0-47
[0] ./d.js 20 bytes {2} {3} {4} {6} {7} {8} [built]
[1] ./f.js 20 bytes {1} {3} {4} {7} {8} [built]
[5] ./c.js 72 bytes {4} {8} [built]
chunk {5} default/main.js (main) 147 bytes >{0}< >{2}< >{3}< >{4}< [entry] [rendered]
> ./ main
[8] ./index.js 147 bytes {5} [built]
chunk {6} default/a.js (a) 216 bytes >{1}< [entry] [rendered]
> ./a a
[0] ./d.js 20 bytes {2} {3} {4} {6} {7} {8} [built]
[2] ./node_modules/x.js 20 bytes {0} {6} [built]
[3] ./node_modules/y.js 20 bytes {0} {6} [built]
[7] ./a.js + 1 modules 156 bytes {2} {6} [built]
| ./a.js 121 bytes [built]
| ./e.js 20 bytes [built]
chunk {7} default/b.js (b) 112 bytes ={0}= [entry] [rendered]
> ./b b
[0] ./d.js 20 bytes {2} {3} {4} {6} {7} {8} [built]
[1] ./f.js 20 bytes {1} {3} {4} {7} {8} [built]
[4] ./b.js 72 bytes {3} {7} [built]
chunk {8} default/c.js (c) 112 bytes ={0}= [entry] [rendered]
> ./c c
[0] ./d.js 20 bytes {2} {3} {4} {6} {7} {8} [built]
[1] ./f.js 20 bytes {1} {3} {4} {7} {8} [built]
[5] ./c.js 72 bytes {4} {8} [built]

View File

@ -98,5 +98,57 @@ module.exports = [
}
},
stats
},
{
name: "custom-chunks-filter",
mode: "production",
entry: {
main: "./",
a: "./a",
b: "./b",
c: "./c"
},
output: {
filename: "default/[name].js"
},
optimization: {
splitChunks: {
minSize: 0,
chunks: chunk => chunk.name !== "a"
}
},
stats
},
{
name: "custom-chunks-filter-in-cache-groups",
mode: "production",
entry: {
main: "./",
a: "./a",
b: "./b",
c: "./c",
vendors: ["x", "y", "z"]
},
output: {
filename: "default/[name].js"
},
optimization: {
splitChunks: {
minSize: 0,
chunks: "all",
cacheGroups: {
default: false,
vendors: {
test: "vendors",
name: "vendors",
enforce: true,
chunks: chunk => chunk.name !== "a"
}
}
}
},
stats
}
];