allow to configure parsers and generators globally

get plugin schemas from root schema
normalize module.parser/generator
add test case
This commit is contained in:
Tobias Koppers 2021-01-05 11:11:02 +01:00
parent 6764e0694c
commit aac7f2e619
23 changed files with 2039 additions and 317 deletions

View File

@ -66,9 +66,13 @@ export type ChunkLoadingType =
| ("jsonp" | "import-scripts" | "require" | "async-node")
| string;
/**
* Specifies the name of each output file on disk. You must **not** specify an absolute path here! The `output.path` option determines the location on disk the files are written to, filename is used solely for naming the individual files.
* Specifies the filename of the output file on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
export type Filename =
export type EntryFilename = FilenameTemplate;
/**
* Specifies the filename template of output files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
export type FilenameTemplate =
| string
| ((
pathData: import("../lib/Compilation").PathData,
@ -352,13 +356,38 @@ export type RuleSetUseItem =
*/
export type RuleSetRules = ("..." | RuleSetRule)[];
/**
* Name of the configuration. Used when loading multiple configurations.
* Generator options for asset modules.
*/
export type Name = string;
export type AssetGeneratorOptions = AssetInlineGeneratorOptions &
AssetResourceGeneratorOptions;
/**
* The options for data url generator.
*/
export type AssetGeneratorDataUrl =
| AssetGeneratorDataUrlOptions
| AssetGeneratorDataUrlFunction;
/**
* Function that executes for module and should return an DataUrl string.
*/
export type AssetGeneratorDataUrlFunction = (
source: string | Buffer,
context: {filename: string; module: import("../lib/Module")}
) => string;
/**
* Function that executes for module and should return whenever asset should be inlined as DataUrl.
*/
export type AssetParserDataUrlFunction = (
source: string | Buffer,
context: {filename: string; module: import("../lib/Module")}
) => boolean;
/**
* Include polyfills or mocks for various node stuff.
*/
export type Node = false | NodeOptions;
/**
* Name of the configuration. Used when loading multiple configurations.
*/
export type Name = string;
/**
* Function acting as plugin.
*/
@ -390,7 +419,7 @@ export type OptimizationSplitChunksSizes =
[k: string]: number;
};
/**
* The filename of asset modules as relative path inside the `output.path` directory.
* The filename of asset modules as relative path inside the 'output.path' directory.
*/
export type AssetModuleFilename =
| string
@ -403,14 +432,9 @@ export type AssetModuleFilename =
*/
export type Charset = boolean;
/**
* The filename of non-initial chunks as relative path inside the `output.path` directory.
* Specifies the filename template of output files of non-initial chunks on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
export type ChunkFilename =
| string
| ((
pathData: import("../lib/Compilation").PathData,
assetInfo?: import("../lib/Compilation").AssetInfo
) => string);
export type ChunkFilename = FilenameTemplate;
/**
* The format of chunks (formats included by default are 'array-push' (web/WebWorker), 'commonjs' (node.js), but others might be added by plugins).
*/
@ -455,6 +479,10 @@ export type EnabledLibraryTypes = LibraryType[];
* List of wasm loading types enabled for use by entry points.
*/
export type EnabledWasmLoadingTypes = WasmLoadingType[];
/**
* Specifies the filename of output files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
export type Filename = FilenameTemplate;
/**
* An expression which is used to address the global object/scope in runtime code.
*/
@ -484,7 +512,7 @@ export type HotUpdateChunkFilename = string;
*/
export type HotUpdateGlobal = string;
/**
* The filename of the Hot Update Main File. It is inside the `output.path` directory.
* The filename of the Hot Update Main File. It is inside the 'output.path' directory.
*/
export type HotUpdateMainFilename = string;
/**
@ -530,7 +558,7 @@ export type PublicPath =
*/
export type ScriptType = false | "text/javascript" | "module";
/**
* The filename of the SourceMaps for the JavaScript files. They are inside the `output.path` directory.
* The filename of the SourceMaps for the JavaScript files. They are inside the 'output.path' directory.
*/
export type SourceMapFilename = string;
/**
@ -546,7 +574,7 @@ export type StrictModuleExceptionHandling = boolean;
*/
export type UniqueName = string;
/**
* The filename of WebAssembly modules as relative path inside the `output.path` directory.
* The filename of WebAssembly modules as relative path inside the 'output.path' directory.
*/
export type WebassemblyModuleFilename = string;
/**
@ -885,9 +913,9 @@ export interface EntryDescription {
*/
dependOn?: string[] | string;
/**
* Specifies the name of each output file on disk. You must **not** specify an absolute path here! The `output.path` option determines the location on disk the files are written to, filename is used solely for naming the individual files.
* Specifies the filename of the output file on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
filename?: Filename;
filename?: EntryFilename;
/**
* Module(s) that are loaded upon startup.
*/
@ -1073,10 +1101,92 @@ export interface ModuleOptions {
* Set the default request for full dynamic dependencies.
*/
exprContextRequest?: string;
/**
* Specify options for each generator.
*/
generator?: {
/**
* Generator options for asset modules.
*/
asset?: AssetGeneratorOptions;
/**
* Generator options for asset/inline modules.
*/
"asset/inline"?: AssetInlineGeneratorOptions;
/**
* Generator options for asset/resource modules.
*/
"asset/resource"?: AssetResourceGeneratorOptions;
/**
* No generator options are supported for this module type.
*/
javascript?: EmptyGeneratorOptions;
/**
* No generator options are supported for this module type.
*/
"javascript/auto"?: EmptyGeneratorOptions;
/**
* No generator options are supported for this module type.
*/
"javascript/dynamic"?: EmptyGeneratorOptions;
/**
* No generator options are supported for this module type.
*/
"javascript/esm"?: EmptyGeneratorOptions;
/**
* Options for generating.
*/
[k: string]: {
[k: string]: any;
};
};
/**
* Don't parse files matching. It's matched against the full resolved request.
*/
noParse?: (RegExp | string | Function)[] | RegExp | string | Function;
/**
* Specify options for each parser.
*/
parser?: {
/**
* Parser options for asset modules.
*/
asset?: AssetParserOptions;
/**
* No parser options are supported for this module type.
*/
"asset/inline"?: EmptyParserOptions;
/**
* No parser options are supported for this module type.
*/
"asset/resource"?: EmptyParserOptions;
/**
* No parser options are supported for this module type.
*/
"asset/source"?: EmptyParserOptions;
/**
* Parser options for javascript modules.
*/
javascript?: JavascriptParserOptions;
/**
* Parser options for javascript modules.
*/
"javascript/auto"?: JavascriptParserOptions;
/**
* Parser options for javascript modules.
*/
"javascript/dynamic"?: JavascriptParserOptions;
/**
* Parser options for javascript modules.
*/
"javascript/esm"?: JavascriptParserOptions;
/**
* Options for parsing.
*/
[k: string]: {
[k: string]: any;
};
};
/**
* An array of rules applied for modules.
*/
@ -1355,6 +1465,121 @@ export interface ResolvePluginInstance {
apply: (resolver: import("enhanced-resolve").Resolver) => void;
[k: string]: any;
}
/**
* Generator options for asset/inline modules.
*/
export interface AssetInlineGeneratorOptions {
/**
* The options for data url generator.
*/
dataUrl?: AssetGeneratorDataUrl;
}
/**
* Options object for data url generation.
*/
export interface AssetGeneratorDataUrlOptions {
/**
* Asset encoding (defaults to base64).
*/
encoding?: false | "base64";
/**
* Asset mimetype (getting from file extension by default).
*/
mimetype?: string;
}
/**
* Generator options for asset/resource modules.
*/
export interface AssetResourceGeneratorOptions {
/**
* Specifies the filename template of output files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
filename?: FilenameTemplate;
}
/**
* No generator options are supported for this module type.
*/
export interface EmptyGeneratorOptions {}
/**
* Parser options for asset modules.
*/
export interface AssetParserOptions {
/**
* The condition for inlining the asset as DataUrl.
*/
dataUrlCondition?: AssetParserDataUrlOptions | AssetParserDataUrlFunction;
}
/**
* Options object for DataUrl condition.
*/
export interface AssetParserDataUrlOptions {
/**
* Maximum size of asset that should be inline as modules. Default: 8kb.
*/
maxSize?: number;
}
/**
* No parser options are supported for this module type.
*/
export interface EmptyParserOptions {}
/**
* Parser options for javascript modules.
*/
export interface JavascriptParserOptions {
/**
* Set the value of `require.amd` and `define.amd`. Or disable AMD support.
*/
amd?: Amd;
/**
* Enable/disable special handling for browserify bundles.
*/
browserify?: boolean;
/**
* Enable/disable parsing of CommonJs syntax.
*/
commonjs?: boolean;
/**
* Enable/disable parsing of EcmaScript Modules syntax.
*/
harmony?: boolean;
/**
* Enable/disable parsing of import() syntax.
*/
import?: boolean;
/**
* Include polyfills or mocks for various node stuff.
*/
node?: Node;
/**
* Enable/disable parsing of require.context syntax.
*/
requireContext?: boolean;
/**
* Enable/disable parsing of require.ensure syntax.
*/
requireEnsure?: boolean;
/**
* Enable/disable parsing of require.include syntax.
*/
requireInclude?: boolean;
/**
* Enable/disable parsing of require.js special syntax like require.config, requirejs.config, require.version and requirejs.onError.
*/
requireJs?: boolean;
/**
* Enable/disable parsing of System.js special syntax like System.import, System.get, System.set and System.register.
*/
system?: boolean;
/**
* Enable/disable parsing of new URL() syntax.
*/
url?: boolean;
/**
* Disable or configure parsing of WebWorker syntax like new Worker() or navigator.serviceWorker.register().
*/
worker?: string[] | boolean;
[k: string]: any;
}
/**
* Options object for node compatibility features.
*/
@ -1697,7 +1922,7 @@ export interface OptimizationSplitChunksCacheGroup {
*/
export interface Output {
/**
* The filename of asset modules as relative path inside the `output.path` directory.
* The filename of asset modules as relative path inside the 'output.path' directory.
*/
assetModuleFilename?: AssetModuleFilename;
/**
@ -1709,7 +1934,7 @@ export interface Output {
*/
charset?: Charset;
/**
* The filename of non-initial chunks as relative path inside the `output.path` directory.
* Specifies the filename template of output files of non-initial chunks on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
chunkFilename?: ChunkFilename;
/**
@ -1765,7 +1990,7 @@ export interface Output {
*/
environment?: Environment;
/**
* Specifies the name of each output file on disk. You must **not** specify an absolute path here! The `output.path` option determines the location on disk the files are written to, filename is used solely for naming the individual files.
* Specifies the filename of output files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
filename?: Filename;
/**
@ -1797,7 +2022,7 @@ export interface Output {
*/
hotUpdateGlobal?: HotUpdateGlobal;
/**
* The filename of the Hot Update Main File. It is inside the `output.path` directory.
* The filename of the Hot Update Main File. It is inside the 'output.path' directory.
*/
hotUpdateMainFilename?: HotUpdateMainFilename;
/**
@ -1845,7 +2070,7 @@ export interface Output {
*/
scriptType?: ScriptType;
/**
* The filename of the SourceMaps for the JavaScript files. They are inside the `output.path` directory.
* The filename of the SourceMaps for the JavaScript files. They are inside the 'output.path' directory.
*/
sourceMapFilename?: SourceMapFilename;
/**
@ -1869,7 +2094,7 @@ export interface Output {
*/
wasmLoading?: WasmLoading;
/**
* The filename of WebAssembly modules as relative path inside the `output.path` directory.
* The filename of WebAssembly modules as relative path inside the 'output.path' directory.
*/
webassemblyModuleFilename?: WebassemblyModuleFilename;
/**
@ -2350,7 +2575,7 @@ export interface EntryDescriptionNormalized {
*/
dependOn?: string[];
/**
* Specifies the name of each output file on disk. You must **not** specify an absolute path here! The `output.path` option determines the location on disk the files are written to, filename is used solely for naming the individual files.
* Specifies the filename of output files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
filename?: Filename;
/**
@ -2384,7 +2609,7 @@ export interface EntryStaticNormalized {
*/
export interface OutputNormalized {
/**
* The filename of asset modules as relative path inside the `output.path` directory.
* The filename of asset modules as relative path inside the 'output.path' directory.
*/
assetModuleFilename?: AssetModuleFilename;
/**
@ -2392,7 +2617,7 @@ export interface OutputNormalized {
*/
charset?: Charset;
/**
* The filename of non-initial chunks as relative path inside the `output.path` directory.
* Specifies the filename template of output files of non-initial chunks on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
chunkFilename?: ChunkFilename;
/**
@ -2448,7 +2673,7 @@ export interface OutputNormalized {
*/
environment?: Environment;
/**
* Specifies the name of each output file on disk. You must **not** specify an absolute path here! The `output.path` option determines the location on disk the files are written to, filename is used solely for naming the individual files.
* Specifies the filename of output files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
filename?: Filename;
/**
@ -2480,7 +2705,7 @@ export interface OutputNormalized {
*/
hotUpdateGlobal?: HotUpdateGlobal;
/**
* The filename of the Hot Update Main File. It is inside the `output.path` directory.
* The filename of the Hot Update Main File. It is inside the 'output.path' directory.
*/
hotUpdateMainFilename?: HotUpdateMainFilename;
/**
@ -2520,7 +2745,7 @@ export interface OutputNormalized {
*/
scriptType?: ScriptType;
/**
* The filename of the SourceMaps for the JavaScript files. They are inside the `output.path` directory.
* The filename of the SourceMaps for the JavaScript files. They are inside the 'output.path' directory.
*/
sourceMapFilename?: SourceMapFilename;
/**
@ -2540,7 +2765,7 @@ export interface OutputNormalized {
*/
wasmLoading?: WasmLoading;
/**
* The filename of WebAssembly modules as relative path inside the `output.path` directory.
* The filename of WebAssembly modules as relative path inside the 'output.path' directory.
*/
webassemblyModuleFilename?: WebassemblyModuleFilename;
/**

View File

@ -1,42 +0,0 @@
/*
* This file was automatically generated.
* DO NOT MODIFY BY HAND.
* Run `yarn special-lint-fix` to update
*/
/**
* Function that executes for module and should return an DataUrl string.
*/
export type DataUrlFunction = (
source: string | Buffer,
context: {filename: string; module: import("../../lib/Module")}
) => string;
export interface AssetModulesPluginGeneratorOptions {
/**
* The options for data url generator.
*/
dataUrl?: DataUrlOptions | DataUrlFunction;
/**
* Template for asset filename.
*/
filename?:
| string
| ((
pathData: import("../../lib/Compilation").PathData,
assetInfo?: import("../../lib/Compilation").AssetInfo
) => string);
}
/**
* Options object for data url generation.
*/
export interface DataUrlOptions {
/**
* Asset encoding (defaults to base64).
*/
encoding?: false | "base64";
/**
* Asset mimetype (getting from file extension by default).
*/
mimetype?: string;
}

View File

@ -1,29 +0,0 @@
/*
* This file was automatically generated.
* DO NOT MODIFY BY HAND.
* Run `yarn special-lint-fix` to update
*/
/**
* Function that executes for module and should return whenever asset should be inlined as DataUrl.
*/
export type DataUrlFunction = (
source: string | Buffer,
context: {filename: string; module: import("../../lib/Module")}
) => boolean;
export interface AssetModulesPluginParserOptions {
/**
* The condition for inlining the asset as DataUrl.
*/
dataUrlCondition?: DataUrlOptions | DataUrlFunction;
}
/**
* Options object for DataUrl condition.
*/
export interface DataUrlOptions {
/**
* Maximum size of asset that should be inline as modules. Default: 8kb.
*/
maxSize?: number;
}

View File

@ -62,6 +62,8 @@ const { parseResource } = require("./util/identifier");
/** @typedef {ResourceData & { data: Record<string, any> }} ResourceDataWithData */
const EMPTY_RESOLVE_OPTIONS = {};
const EMPTY_PARSER_OPTIONS = {};
const EMPTY_GENERATOR_OPTIONS = {};
const MATCH_RESOURCE_REGEX = /^([^!]+)!=!/;
@ -122,6 +124,28 @@ const needCalls = (times, callback) => {
};
};
const mergeGlobalOptions = (globalOptions, type, localOptions) => {
const parts = type.split("/");
let result;
let current = "";
for (const part of parts) {
current = current ? `${current}/${part}` : part;
const options = globalOptions[current];
if (typeof options === "object") {
if (result === undefined) {
result = options;
} else {
result = cachedCleverMerge(result, options);
}
}
}
if (result === undefined) {
return localOptions;
} else {
return cachedCleverMerge(result, localOptions);
}
};
// TODO webpack 6 remove
const deprecationChangedHookMessage = name =>
`NormalModuleFactory.${name} is no longer a waterfall hook, but a bailing hook instead. ` +
@ -210,6 +234,8 @@ class NormalModuleFactory extends ModuleFactory {
: () => true;
this.context = context || "";
this.fs = fs;
this._globalParserOptions = options.parser;
this._globalGeneratorOptions = options.generator;
/**
* @type {Map<string, WeakMap<Object, TODO>>}
*/
@ -783,7 +809,7 @@ Add the extension to the request.`;
);
}
getParser(type, parserOptions = EMPTY_RESOLVE_OPTIONS) {
getParser(type, parserOptions = EMPTY_PARSER_OPTIONS) {
let cache = this.parserCache.get(type);
if (cache === undefined) {
@ -807,6 +833,11 @@ Add the extension to the request.`;
* @returns {Parser} parser
*/
createParser(type, parserOptions = {}) {
parserOptions = mergeGlobalOptions(
this._globalParserOptions,
type,
parserOptions
);
const parser = this.hooks.createParser.for(type).call(parserOptions);
if (!parser) {
throw new Error(`No parser registered for ${type}`);
@ -815,7 +846,7 @@ Add the extension to the request.`;
return parser;
}
getGenerator(type, generatorOptions = EMPTY_RESOLVE_OPTIONS) {
getGenerator(type, generatorOptions = EMPTY_GENERATOR_OPTIONS) {
let cache = this.generatorCache.get(type);
if (cache === undefined) {
@ -834,6 +865,11 @@ Add the extension to the request.`;
}
createGenerator(type, generatorOptions = {}) {
generatorOptions = mergeGlobalOptions(
this._globalGeneratorOptions,
type,
generatorOptions
);
const generator = this.hooks.createGenerator
.for(type)
.call(generatorOptions);

View File

@ -14,7 +14,7 @@ const createHash = require("../util/createHash");
const { makePathsRelative } = require("../util/identifier");
/** @typedef {import("webpack-sources").Source} Source */
/** @typedef {import("../../declarations/plugins/AssetModulesPluginGenerator").AssetModulesPluginGeneratorOptions} AssetModulesPluginGeneratorOptions */
/** @typedef {import("../../declarations/WebpackOptions").AssetGeneratorOptions} AssetGeneratorOptions */
/** @typedef {import("../Compilation")} Compilation */
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
@ -30,7 +30,7 @@ const JS_AND_ASSET_TYPES = new Set(["javascript", "asset"]);
class AssetGenerator extends Generator {
/**
* @param {Compilation} compilation the compilation
* @param {AssetModulesPluginGeneratorOptions["dataUrl"]=} dataUrlOptions the options for the data url
* @param {AssetGeneratorOptions["dataUrl"]=} dataUrlOptions the options for the data url
* @param {string=} filename override for output.assetModuleFilename
*/
constructor(compilation, dataUrlOptions, filename) {

View File

@ -6,6 +6,7 @@
"use strict";
const { validate } = require("schema-utils");
const { cleverMerge } = require("../util/cleverMerge");
const { compareModulesByIdentifier } = require("../util/comparators");
const memoize = require("../util/memoize");
@ -14,37 +15,20 @@ const memoize = require("../util/memoize");
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Module")} Module */
const getGeneratorSchema = memoize(() =>
require("../../schemas/plugins/AssetModulesPluginGenerator.json")
);
const getSchema = name => {
const { definitions } = require("../../schemas/WebpackOptions.json");
return {
definitions,
oneOf: [{ $ref: `#/definitions/${name}` }]
};
};
const getGeneratorSchemaMap = {
asset: getGeneratorSchema,
"asset/resource": memoize(() => {
const base = getGeneratorSchema();
return {
...base,
properties: {
...base.properties,
dataUrl: false
}
};
}),
"asset/inline": memoize(() => {
const base = getGeneratorSchema();
return {
...base,
properties: {
...base.properties,
filename: false
}
};
})
asset: memoize(() => getSchema("AssetGeneratorOptions")),
"asset/resource": memoize(() => getSchema("AssetResourceGeneratorOptions")),
"asset/inline": memoize(() => getSchema("AssetInlineGeneratorOptions"))
};
const getParserSchema = memoize(() =>
require("../../schemas/plugins/AssetModulesPluginParser.json")
);
const getParserSchema = memoize(() => getSchema("AssetParserOptions"));
const getAssetGenerator = memoize(() => require("./AssetGenerator"));
const getAssetParser = memoize(() => require("./AssetParser"));
const getAssetSourceGenerator = memoize(() =>
@ -71,6 +55,10 @@ class AssetModulesPlugin {
name: "Asset Modules Plugin",
baseDataPath: "parser"
});
parserOptions = cleverMerge(
compiler.options.module.parser.asset,
parserOptions
);
let dataUrlCondition = parserOptions.dataUrlCondition;
if (!dataUrlCondition || typeof dataUrlCondition === "object") {

View File

@ -7,13 +7,13 @@
const Parser = require("../Parser");
/** @typedef {import("../../declarations/plugins/AssetModulesPluginParser").AssetModulesPluginParserOptions} AssetModulesPluginParserOptions */
/** @typedef {import("../../declarations/WebpackOptions").AssetParserOptions} AssetParserOptions */
/** @typedef {import("../Parser").ParserState} ParserState */
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
class AssetParser extends Parser {
/**
* @param {AssetModulesPluginParserOptions["dataUrlCondition"] | boolean} dataUrlCondition condition for inlining as DataUrl
* @param {AssetParserOptions["dataUrlCondition"] | boolean} dataUrlCondition condition for inlining as DataUrl
*/
constructor(dataUrlCondition) {
super();

View File

@ -15,11 +15,13 @@ const {
} = require("./target");
/** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptions */
/** @typedef {import("../../declarations/WebpackOptions").EntryDescription} EntryDescription */
/** @typedef {import("../../declarations/WebpackOptions").EntryNormalized} Entry */
/** @typedef {import("../../declarations/WebpackOptions").Experiments} Experiments */
/** @typedef {import("../../declarations/WebpackOptions").ExternalsPresets} ExternalsPresets */
/** @typedef {import("../../declarations/WebpackOptions").ExternalsType} ExternalsType */
/** @typedef {import("../../declarations/WebpackOptions").InfrastructureLogging} InfrastructureLogging */
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
/** @typedef {import("../../declarations/WebpackOptions").Library} Library */
/** @typedef {import("../../declarations/WebpackOptions").LibraryName} LibraryName */
/** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
@ -179,7 +181,8 @@ const applyWebpackOptionsDefaults = options => {
targetProperties,
outputModule: options.experiments.outputModule,
development,
entry: options.entry
entry: options.entry,
module: options.module
});
applyExternalsPresetsDefaults(options.externalsPresets, { targetProperties });
@ -343,6 +346,12 @@ const applySnapshotDefaults = (snapshot, { production }) => {
);
};
/**
* @param {JavascriptParserOptions} options options
* @returns {void}
*/
const applyJavascriptParserOptionsDefaults = options => {};
/**
* @param {ModuleOptions} module options
* @param {Object} options options
@ -379,6 +388,15 @@ const applyModuleDefaults = (
D(module, "unsafeCache", false);
}
F(module.parser, "asset", () => ({}));
F(module.parser.asset, "dataUrlCondition", () => ({}));
if (typeof module.parser.asset.dataUrlCondition === "object") {
D(module.parser.asset.dataUrlCondition, "maxSize", 8096);
}
F(module.parser, "javascript", () => ({}));
applyJavascriptParserOptionsDefaults(module.parser.javascript);
A(module, "defaultRules", () => {
const esm = {
type: "javascript/esm",
@ -500,11 +518,12 @@ const applyModuleDefaults = (
* @param {boolean} options.outputModule is outputModule experiment enabled
* @param {boolean} options.development is development mode
* @param {Entry} options.entry entry option
* @param {ModuleOptions} options.module module option
* @returns {void}
*/
const applyOutputDefaults = (
output,
{ context, targetProperties: tp, outputModule, development, entry }
{ context, targetProperties: tp, outputModule, development, entry, module }
) => {
/**
* @param {Library=} library the library option
@ -675,17 +694,25 @@ const applyOutputDefaults = (
F(output.environment, "dynamicImport", () => tp && tp.dynamicImport);
F(output.environment, "module", () => tp && tp.module);
/**
* @param {function(EntryDescription): void} fn iterator
* @returns {void}
*/
const forEachEntry = fn => {
for (const name of Object.keys(entry)) {
fn(entry[name]);
}
};
A(output, "enabledLibraryTypes", () => {
const enabledLibraryTypes = [];
if (output.library) {
enabledLibraryTypes.push(output.library.type);
}
for (const name of Object.keys(entry)) {
const desc = entry[name];
forEachEntry(desc => {
if (desc.library) {
enabledLibraryTypes.push(desc.library.type);
}
}
});
return enabledLibraryTypes;
});
@ -697,12 +724,11 @@ const applyOutputDefaults = (
if (output.workerChunkLoading) {
enabledChunkLoadingTypes.add(output.workerChunkLoading);
}
for (const name of Object.keys(entry)) {
const desc = entry[name];
forEachEntry(desc => {
if (desc.chunkLoading) {
enabledChunkLoadingTypes.add(desc.chunkLoading);
}
}
});
return Array.from(enabledChunkLoadingTypes);
});
@ -714,12 +740,11 @@ const applyOutputDefaults = (
if (output.workerWasmLoading) {
enabledWasmLoadingTypes.add(output.workerWasmLoading);
}
for (const name of Object.keys(entry)) {
const desc = entry[name];
forEachEntry(desc => {
if (desc.wasmLoading) {
enabledWasmLoadingTypes.add(desc.wasmLoading);
}
}
});
return Array.from(enabledWasmLoadingTypes);
});
};

View File

@ -40,6 +40,15 @@ const handledDeprecatedNoEmitOnErrors = util.deprecate(
const nestedConfig = (value, fn) =>
value === undefined ? fn(/** @type {T} */ ({})) : fn(value);
/**
* @template T
* @param {T|undefined} value value or not
* @returns {T} result value
*/
const cloneObject = value => {
return /** @type {T} */ ({ ...value });
};
/**
* @template T
* @template R
@ -103,12 +112,7 @@ const getNormalizedWebpackOptions = config => {
case "filesystem":
return {
type: "filesystem",
buildDependencies: nestedConfig(
cache.buildDependencies,
buildDependencies => ({
...buildDependencies
})
),
buildDependencies: cloneObject(cache.buildDependencies),
cacheDirectory: cache.cacheDirectory,
cacheLocation: cache.cacheLocation,
hashAlgorithm: cache.hashAlgorithm,
@ -143,14 +147,9 @@ const getNormalizedWebpackOptions = config => {
config.entry
)
: getNormalizedEntryStatic(config.entry),
experiments: nestedConfig(config.experiments, experiments => ({
...experiments
})),
experiments: cloneObject(config.experiments),
externals: config.externals,
externalsPresets: nestedConfig(
config.externalsPresets,
externalsPresets => ({ ...externalsPresets })
),
externalsPresets: cloneObject(config.externalsPresets),
externalsType: config.externalsType,
ignoreWarnings: config.ignoreWarnings
? config.ignoreWarnings.map(ignore => {
@ -177,16 +176,13 @@ const getNormalizedWebpackOptions = config => {
};
})
: undefined,
infrastructureLogging: nestedConfig(
config.infrastructureLogging,
infrastructureLogging => ({
...infrastructureLogging
})
),
loader: nestedConfig(config.loader, loader => ({ ...loader })),
infrastructureLogging: cloneObject(config.infrastructureLogging),
loader: cloneObject(config.loader),
mode: config.mode,
module: nestedConfig(config.module, module => ({
...module,
parser: cloneObject(module.parser),
generator: cloneObject(module.generator),
rules: nestedArray(module.rules, r => [...r])
})),
name: config.name,
@ -211,12 +207,7 @@ const getNormalizedWebpackOptions = config => {
defaultSizeTypes: splitChunks.defaultSizeTypes
? [...splitChunks.defaultSizeTypes]
: ["..."],
cacheGroups: nestedConfig(
splitChunks.cacheGroups,
cacheGroups => ({
...cacheGroups
})
)
cacheGroups: cloneObject(splitChunks.cacheGroups)
}
),
emitOnErrors:
@ -257,9 +248,7 @@ const getNormalizedWebpackOptions = config => {
output.devtoolFallbackModuleFilenameTemplate,
devtoolModuleFilenameTemplate: output.devtoolModuleFilenameTemplate,
devtoolNamespace: output.devtoolNamespace,
environment: nestedConfig(output.environment, environment => ({
...environment
})),
environment: cloneObject(output.environment),
enabledChunkLoadingTypes: output.enabledChunkLoadingTypes
? [...output.enabledChunkLoadingTypes]
: ["..."],
@ -335,13 +324,9 @@ const getNormalizedWebpackOptions = config => {
: config.recordsPath,
resolve: nestedConfig(config.resolve, resolve => ({
...resolve,
byDependency: keyedNestedConfig(resolve.byDependency, resolve => ({
...resolve
}))
})),
resolveLoader: nestedConfig(config.resolveLoader, resolve => ({
...resolve
byDependency: keyedNestedConfig(resolve.byDependency, cloneObject)
})),
resolveLoader: cloneObject(config.resolveLoader),
snapshot: nestedConfig(config.snapshot, snapshot => ({
resolveBuildDependencies: optionalNestedConfig(
snapshot.resolveBuildDependencies,
@ -390,9 +375,7 @@ const getNormalizedWebpackOptions = config => {
}),
target: config.target,
watch: config.watch,
watchOptions: nestedConfig(config.watchOptions, watchOptions => ({
...watchOptions
}))
watchOptions: cloneObject(config.watchOptions)
};
};

View File

@ -98,6 +98,7 @@ class HarmonyModulesPlugin {
);
const handler = (parser, parserOptions) => {
// TODO webpack 6: rename harmony to esm or module
if (parserOptions.harmony !== undefined && !parserOptions.harmony)
return;

View File

@ -13,8 +13,66 @@
}
]
},
"AssetGeneratorDataUrl": {
"description": "The options for data url generator.",
"anyOf": [
{
"$ref": "#/definitions/AssetGeneratorDataUrlOptions"
},
{
"$ref": "#/definitions/AssetGeneratorDataUrlFunction"
}
]
},
"AssetGeneratorDataUrlFunction": {
"description": "Function that executes for module and should return an DataUrl string.",
"instanceof": "Function",
"tsType": "((source: string | Buffer, context: { filename: string, module: import('../lib/Module') }) => string)"
},
"AssetGeneratorDataUrlOptions": {
"description": "Options object for data url generation.",
"type": "object",
"additionalProperties": false,
"properties": {
"encoding": {
"description": "Asset encoding (defaults to base64).",
"enum": [false, "base64"]
},
"mimetype": {
"description": "Asset mimetype (getting from file extension by default).",
"type": "string"
}
}
},
"AssetGeneratorOptions": {
"description": "Generator options for asset modules.",
"type": "object",
"implements": [
"#/definitions/AssetInlineGeneratorOptions",
"#/definitions/AssetResourceGeneratorOptions"
],
"additionalProperties": false,
"properties": {
"dataUrl": {
"$ref": "#/definitions/AssetGeneratorDataUrl"
},
"filename": {
"$ref": "#/definitions/FilenameTemplate"
}
}
},
"AssetInlineGeneratorOptions": {
"description": "Generator options for asset/inline modules.",
"type": "object",
"additionalProperties": false,
"properties": {
"dataUrl": {
"$ref": "#/definitions/AssetGeneratorDataUrl"
}
}
},
"AssetModuleFilename": {
"description": "The filename of asset modules as relative path inside the `output.path` directory.",
"description": "The filename of asset modules as relative path inside the 'output.path' directory.",
"anyOf": [
{
"type": "string",
@ -26,6 +84,50 @@
}
]
},
"AssetParserDataUrlFunction": {
"description": "Function that executes for module and should return whenever asset should be inlined as DataUrl.",
"instanceof": "Function",
"tsType": "((source: string | Buffer, context: { filename: string, module: import('../lib/Module') }) => boolean)"
},
"AssetParserDataUrlOptions": {
"description": "Options object for DataUrl condition.",
"type": "object",
"additionalProperties": false,
"properties": {
"maxSize": {
"description": "Maximum size of asset that should be inline as modules. Default: 8kb.",
"type": "number"
}
}
},
"AssetParserOptions": {
"description": "Parser options for asset modules.",
"type": "object",
"additionalProperties": false,
"properties": {
"dataUrlCondition": {
"description": "The condition for inlining the asset as DataUrl.",
"anyOf": [
{
"$ref": "#/definitions/AssetParserDataUrlOptions"
},
{
"$ref": "#/definitions/AssetParserDataUrlFunction"
}
]
}
}
},
"AssetResourceGeneratorOptions": {
"description": "Generator options for asset/resource modules.",
"type": "object",
"additionalProperties": false,
"properties": {
"filename": {
"$ref": "#/definitions/FilenameTemplate"
}
}
},
"AuxiliaryComment": {
"description": "Add a comment in the UMD wrapper.",
"anyOf": [
@ -74,16 +176,10 @@
"type": "boolean"
},
"ChunkFilename": {
"description": "The filename of non-initial chunks as relative path inside the `output.path` directory.",
"anyOf": [
"description": "Specifies the filename template of output files of non-initial chunks on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.",
"oneOf": [
{
"type": "string",
"absolutePath": false,
"minLength": 1
},
{
"instanceof": "Function",
"tsType": "((pathData: import(\"../lib/Compilation\").PathData, assetInfo?: import(\"../lib/Compilation\").AssetInfo) => string)"
"$ref": "#/definitions/FilenameTemplate"
}
]
},
@ -193,6 +289,16 @@
"description": "Module namespace to use when interpolating filename template string for the sources array in a generated SourceMap. Defaults to `output.library` if not set. It's useful for avoiding runtime collisions in sourcemaps from multiple webpack projects built as libraries.",
"type": "string"
},
"EmptyGeneratorOptions": {
"description": "No generator options are supported for this module type.",
"type": "object",
"additionalProperties": false
},
"EmptyParserOptions": {
"description": "No parser options are supported for this module type.",
"type": "object",
"additionalProperties": false
},
"EnabledChunkLoadingTypes": {
"description": "List of chunk loading types enabled for use by entry points.",
"type": "array",
@ -255,7 +361,7 @@
]
},
"filename": {
"$ref": "#/definitions/Filename"
"$ref": "#/definitions/EntryFilename"
},
"import": {
"$ref": "#/definitions/EntryItem"
@ -326,6 +432,14 @@
"instanceof": "Function",
"tsType": "(() => Promise<EntryStaticNormalized>)"
},
"EntryFilename": {
"description": "Specifies the filename of the output file on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.",
"oneOf": [
{
"$ref": "#/definitions/FilenameTemplate"
}
]
},
"EntryItem": {
"description": "Module(s) that are loaded upon startup.",
"anyOf": [
@ -677,7 +791,15 @@
"required": ["type"]
},
"Filename": {
"description": "Specifies the name of each output file on disk. You must **not** specify an absolute path here! The `output.path` option determines the location on disk the files are written to, filename is used solely for naming the individual files.",
"description": "Specifies the filename of output files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.",
"oneOf": [
{
"$ref": "#/definitions/FilenameTemplate"
}
]
},
"FilenameTemplate": {
"description": "Specifies the filename template of output files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.",
"anyOf": [
{
"type": "string",
@ -777,7 +899,7 @@
"type": "string"
},
"HotUpdateMainFilename": {
"description": "The filename of the Hot Update Main File. It is inside the `output.path` directory.",
"description": "The filename of the Hot Update Main File. It is inside the 'output.path' directory.",
"type": "string",
"absolutePath": false
},
@ -865,6 +987,75 @@
}
}
},
"JavascriptParserOptions": {
"description": "Parser options for javascript modules.",
"type": "object",
"additionalProperties": true,
"properties": {
"amd": {
"$ref": "#/definitions/Amd"
},
"browserify": {
"description": "Enable/disable special handling for browserify bundles.",
"type": "boolean"
},
"commonjs": {
"description": "Enable/disable parsing of CommonJs syntax.",
"type": "boolean"
},
"harmony": {
"description": "Enable/disable parsing of EcmaScript Modules syntax.",
"type": "boolean"
},
"import": {
"description": "Enable/disable parsing of import() syntax.",
"type": "boolean"
},
"node": {
"$ref": "#/definitions/Node"
},
"requireContext": {
"description": "Enable/disable parsing of require.context syntax.",
"type": "boolean"
},
"requireEnsure": {
"description": "Enable/disable parsing of require.ensure syntax.",
"type": "boolean"
},
"requireInclude": {
"description": "Enable/disable parsing of require.include syntax.",
"type": "boolean"
},
"requireJs": {
"description": "Enable/disable parsing of require.js special syntax like require.config, requirejs.config, require.version and requirejs.onError.",
"type": "boolean"
},
"system": {
"description": "Enable/disable parsing of System.js special syntax like System.import, System.get, System.set and System.register.",
"type": "boolean"
},
"url": {
"description": "Enable/disable parsing of new URL() syntax.",
"type": "boolean"
},
"worker": {
"description": "Disable or configure parsing of WebWorker syntax like new Worker() or navigator.serviceWorker.register().",
"anyOf": [
{
"type": "array",
"items": {
"description": "Specify a syntax that should be parsed as WebWorker reference. 'Abc' handles 'new Abc()', 'Abc from xyz' handles 'import { Abc } from \"xyz\"; new Abc()', 'abc()' handles 'abc()', and combinations are also possible.",
"type": "string",
"minLength": 1
}
},
{
"type": "boolean"
}
]
}
}
},
"Library": {
"description": "Make the output files a library, exporting the exports of the entry point.",
"anyOf": [
@ -1081,6 +1272,38 @@
"description": "Set the default request for full dynamic dependencies.",
"type": "string"
},
"generator": {
"description": "Specify options for each generator.",
"type": "object",
"additionalProperties": {
"description": "Options for generating.",
"type": "object",
"additionalProperties": true
},
"properties": {
"asset": {
"$ref": "#/definitions/AssetGeneratorOptions"
},
"asset/inline": {
"$ref": "#/definitions/AssetInlineGeneratorOptions"
},
"asset/resource": {
"$ref": "#/definitions/AssetResourceGeneratorOptions"
},
"javascript": {
"$ref": "#/definitions/EmptyGeneratorOptions"
},
"javascript/auto": {
"$ref": "#/definitions/EmptyGeneratorOptions"
},
"javascript/dynamic": {
"$ref": "#/definitions/EmptyGeneratorOptions"
},
"javascript/esm": {
"$ref": "#/definitions/EmptyGeneratorOptions"
}
}
},
"noParse": {
"description": "Don't parse files matching. It's matched against the full resolved request.",
"anyOf": [
@ -1123,6 +1346,41 @@
}
]
},
"parser": {
"description": "Specify options for each parser.",
"type": "object",
"additionalProperties": {
"description": "Options for parsing.",
"type": "object",
"additionalProperties": true
},
"properties": {
"asset": {
"$ref": "#/definitions/AssetParserOptions"
},
"asset/inline": {
"$ref": "#/definitions/EmptyParserOptions"
},
"asset/resource": {
"$ref": "#/definitions/EmptyParserOptions"
},
"asset/source": {
"$ref": "#/definitions/EmptyParserOptions"
},
"javascript": {
"$ref": "#/definitions/JavascriptParserOptions"
},
"javascript/auto": {
"$ref": "#/definitions/JavascriptParserOptions"
},
"javascript/dynamic": {
"$ref": "#/definitions/JavascriptParserOptions"
},
"javascript/esm": {
"$ref": "#/definitions/JavascriptParserOptions"
}
}
},
"rules": {
"description": "An array of rules applied for modules.",
"oneOf": [
@ -3145,7 +3403,7 @@
}
},
"SourceMapFilename": {
"description": "The filename of the SourceMaps for the JavaScript files. They are inside the `output.path` directory.",
"description": "The filename of the SourceMaps for the JavaScript files. They are inside the 'output.path' directory.",
"type": "string",
"absolutePath": false
},
@ -3670,7 +3928,7 @@
}
},
"WebassemblyModuleFilename": {
"description": "The filename of WebAssembly modules as relative path inside the `output.path` directory.",
"description": "The filename of WebAssembly modules as relative path inside the 'output.path' directory.",
"type": "string",
"absolutePath": false
},

View File

@ -1,53 +0,0 @@
{
"definitions": {
"DataUrlFunction": {
"description": "Function that executes for module and should return an DataUrl string.",
"instanceof": "Function",
"tsType": "((source: string | Buffer, context: { filename: string, module: import('../../lib/Module') }) => string)"
},
"DataUrlOptions": {
"description": "Options object for data url generation.",
"type": "object",
"additionalProperties": false,
"properties": {
"encoding": {
"description": "Asset encoding (defaults to base64).",
"enum": [false, "base64"]
},
"mimetype": {
"description": "Asset mimetype (getting from file extension by default).",
"type": "string"
}
}
}
},
"title": "AssetModulesPluginGeneratorOptions",
"type": "object",
"additionalProperties": false,
"properties": {
"dataUrl": {
"description": "The options for data url generator.",
"anyOf": [
{
"$ref": "#/definitions/DataUrlOptions"
},
{
"$ref": "#/definitions/DataUrlFunction"
}
]
},
"filename": {
"description": "Template for asset filename.",
"anyOf": [
{
"type": "string",
"absolutePath": false
},
{
"instanceof": "Function",
"tsType": "((pathData: import(\"../../lib/Compilation\").PathData, assetInfo?: import(\"../../lib/Compilation\").AssetInfo) => string)"
}
]
}
}
}

View File

@ -1,36 +0,0 @@
{
"definitions": {
"DataUrlFunction": {
"description": "Function that executes for module and should return whenever asset should be inlined as DataUrl.",
"instanceof": "Function",
"tsType": "((source: string | Buffer, context: { filename: string, module: import('../../lib/Module') }) => boolean)"
},
"DataUrlOptions": {
"description": "Options object for DataUrl condition.",
"type": "object",
"additionalProperties": false,
"properties": {
"maxSize": {
"description": "Maximum size of asset that should be inline as modules. Default: 8kb.",
"type": "number"
}
}
}
},
"title": "AssetModulesPluginParserOptions",
"type": "object",
"additionalProperties": false,
"properties": {
"dataUrlCondition": {
"description": "The condition for inlining the asset as DataUrl.",
"anyOf": [
{
"$ref": "#/definitions/DataUrlOptions"
},
{
"$ref": "#/definitions/DataUrlFunction"
}
]
}
}
}

View File

@ -193,6 +193,15 @@ describe("Defaults", () => {
"exprContextRecursive": true,
"exprContextRegExp": false,
"exprContextRequest": ".",
"generator": Object {},
"parser": Object {
"asset": Object {
"dataUrlCondition": Object {
"maxSize": 8096,
},
},
"javascript": Object {},
},
"rules": Array [],
"strictExportPresence": false,
"strictThisContextOnImports": false,

View File

@ -124,7 +124,7 @@ describe("Validation", () => {
-> A module that is loaded upon startup. Only the last one is exported.
- configuration.output.filename should be one of these:
non-empty string | function
-> Specifies the name of each output file on disk. You must **not** specify an absolute path here! The \`output.path\` option determines the location on disk the files are written to, filename is used solely for naming the individual files.
-> Specifies the filename template of output files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
Details:
* configuration.output.filename should be a non-empty string.
* configuration.output.filename should be an instance of function."
@ -151,7 +151,7 @@ describe("Validation", () => {
-> A module that is loaded upon startup. Only the last one is exported.
- configuration[1].output.filename should be one of these:
non-empty string | function
-> Specifies the name of each output file on disk. You must **not** specify an absolute path here! The \`output.path\` option determines the location on disk the files are written to, filename is used solely for naming the individual files.
-> Specifies the filename template of output files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
Details:
* configuration[1].output.filename should be a non-empty string.
* configuration[1].output.filename should be an instance of function."

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
import png from "../_images/file.png";
import svg from "../_images/file.svg?inline";
import jpg from "../_images/file.jpg";
it("should output various asset types", () => {
expect(png).toMatch(/^[\da-f]{20}\.png$/);
expect(svg).toMatch(/^data:image\/svg\+xml,/);
expect(jpg).toMatch(/^DATA:image\/jpeg;base64,[0-9a-zA-Z+/]+=*$/);
});

View File

@ -0,0 +1,44 @@
const svgToMiniDataURI = require("mini-svg-data-uri");
const mimeTypes = require("mime-types");
/** @type {import("../../../../").Configuration} */
module.exports = {
mode: "development",
module: {
parser: {
asset: {
dataUrlCondition: (source, { filename }) => {
return filename.includes("?inline");
}
}
},
generator: {
asset: {
dataUrl: (source, { module }) => {
const mimeType = mimeTypes.lookup(module.nameForCondition());
if (mimeType === "image/svg+xml") {
if (typeof source !== "string") {
source = source.toString();
}
return svgToMiniDataURI(source);
}
const encodedContent = source.toString("base64");
return `DATA:${mimeType};base64,${encodedContent}`;
}
}
},
rules: [
{
test: /\.(png|svg)$/,
type: "asset"
},
{
test: /\.jpg$/,
type: "asset/inline"
}
]
}
};

View File

@ -1,3 +1,4 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
mode: "development",
module: {

View File

@ -1,6 +1,7 @@
const svgToMiniDataURI = require("mini-svg-data-uri");
const mimeTypes = require("mime-types");
/** @type {import("../../../../").Configuration} */
module.exports = {
mode: "development",
module: {

View File

@ -1,3 +1,4 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
mode: "development",
module: {

251
types.d.ts vendored
View File

@ -212,7 +212,74 @@ declare interface AssetEmittedInfo {
outputPath: string;
targetPath: string;
}
/**
* Options object for data url generation.
*/
declare interface AssetGeneratorDataUrlOptions {
/**
* Asset encoding (defaults to base64).
*/
encoding?: false | "base64";
/**
* Asset mimetype (getting from file extension by default).
*/
mimetype?: string;
}
type AssetGeneratorOptions = AssetInlineGeneratorOptions &
AssetResourceGeneratorOptions;
type AssetInfo = KnownAssetInfo & Record<string, any>;
/**
* Generator options for asset/inline modules.
*/
declare interface AssetInlineGeneratorOptions {
/**
* The options for data url generator.
*/
dataUrl?:
| AssetGeneratorDataUrlOptions
| ((
source: string | Buffer,
context: { filename: string; module: Module }
) => string);
}
/**
* Options object for DataUrl condition.
*/
declare interface AssetParserDataUrlOptions {
/**
* Maximum size of asset that should be inline as modules. Default: 8kb.
*/
maxSize?: number;
}
/**
* Parser options for asset modules.
*/
declare interface AssetParserOptions {
/**
* The condition for inlining the asset as DataUrl.
*/
dataUrlCondition?:
| AssetParserDataUrlOptions
| ((
source: string | Buffer,
context: { filename: string; module: Module }
) => boolean);
}
/**
* Generator options for asset/resource modules.
*/
declare interface AssetResourceGeneratorOptions {
/**
* Specifies the filename template of output files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
filename?: string | ((pathData: PathData, assetInfo?: AssetInfo) => string);
}
declare abstract class AsyncDependenciesBlock extends DependenciesBlock {
groupOptions: RawChunkGroupOptions & { name?: string } & {
entryOptions?: EntryOptions;
@ -2535,6 +2602,16 @@ declare class ElectronTargetPlugin {
*/
apply(compiler: Compiler): void;
}
/**
* No generator options are supported for this module type.
*/
declare interface EmptyGeneratorOptions {}
/**
* No parser options are supported for this module type.
*/
declare interface EmptyParserOptions {}
declare class EnableChunkLoadingPlugin {
constructor(type: string);
type: string;
@ -2595,7 +2672,7 @@ declare interface EntryDescription {
dependOn?: string | string[];
/**
* Specifies the name of each output file on disk. You must **not** specify an absolute path here! The `output.path` option determines the location on disk the files are written to, filename is used solely for naming the individual files.
* Specifies the filename of the output file on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
filename?: string | ((pathData: PathData, assetInfo?: AssetInfo) => string);
@ -2635,7 +2712,7 @@ declare interface EntryDescriptionNormalized {
dependOn?: string[];
/**
* Specifies the name of each output file on disk. You must **not** specify an absolute path here! The `output.path` option determines the location on disk the files are written to, filename is used solely for naming the individual files.
* Specifies the filename of output files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
filename?: string | ((pathData: PathData, assetInfo?: AssetInfo) => string);
@ -4347,6 +4424,78 @@ declare class JavascriptParser extends Parser {
static ALLOWED_MEMBER_TYPES_EXPRESSION: 2;
static ALLOWED_MEMBER_TYPES_CALL_EXPRESSION: 1;
}
/**
* Parser options for javascript modules.
*/
declare interface JavascriptParserOptions {
[index: string]: any;
/**
* Set the value of `require.amd` and `define.amd`. Or disable AMD support.
*/
amd?: false | { [index: string]: any };
/**
* Enable/disable special handling for browserify bundles.
*/
browserify?: boolean;
/**
* Enable/disable parsing of CommonJs syntax.
*/
commonjs?: boolean;
/**
* Enable/disable parsing of EcmaScript Modules syntax.
*/
harmony?: boolean;
/**
* Enable/disable parsing of import() syntax.
*/
import?: boolean;
/**
* Include polyfills or mocks for various node stuff.
*/
node?: false | NodeOptions;
/**
* Enable/disable parsing of require.context syntax.
*/
requireContext?: boolean;
/**
* Enable/disable parsing of require.ensure syntax.
*/
requireEnsure?: boolean;
/**
* Enable/disable parsing of require.include syntax.
*/
requireInclude?: boolean;
/**
* Enable/disable parsing of require.js special syntax like require.config, requirejs.config, require.version and requirejs.onError.
*/
requireJs?: boolean;
/**
* Enable/disable parsing of System.js special syntax like System.import, System.get, System.set and System.register.
*/
system?: boolean;
/**
* Enable/disable parsing of new URL() syntax.
*/
url?: boolean;
/**
* Disable or configure parsing of WebWorker syntax like new Worker() or navigator.serviceWorker.register().
*/
worker?: boolean | string[];
}
declare class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
constructor(runtimeRequirements?: any);
static getCompilationHooks(
@ -5297,11 +5446,85 @@ declare interface ModuleOptions {
*/
exprContextRequest?: string;
/**
* Specify options for each generator.
*/
generator?: {
[index: string]: { [index: string]: any };
/**
* Generator options for asset modules.
*/
asset?: AssetGeneratorOptions;
/**
* Generator options for asset/inline modules.
*/
"asset/inline"?: AssetInlineGeneratorOptions;
/**
* Generator options for asset/resource modules.
*/
"asset/resource"?: AssetResourceGeneratorOptions;
/**
* No generator options are supported for this module type.
*/
javascript?: EmptyGeneratorOptions;
/**
* No generator options are supported for this module type.
*/
"javascript/auto"?: EmptyGeneratorOptions;
/**
* No generator options are supported for this module type.
*/
"javascript/dynamic"?: EmptyGeneratorOptions;
/**
* No generator options are supported for this module type.
*/
"javascript/esm"?: EmptyGeneratorOptions;
};
/**
* Don't parse files matching. It's matched against the full resolved request.
*/
noParse?: string | Function | RegExp | (string | Function | RegExp)[];
/**
* Specify options for each parser.
*/
parser?: {
[index: string]: { [index: string]: any };
/**
* Parser options for asset modules.
*/
asset?: AssetParserOptions;
/**
* No parser options are supported for this module type.
*/
"asset/inline"?: EmptyParserOptions;
/**
* No parser options are supported for this module type.
*/
"asset/resource"?: EmptyParserOptions;
/**
* No parser options are supported for this module type.
*/
"asset/source"?: EmptyParserOptions;
/**
* Parser options for javascript modules.
*/
javascript?: JavascriptParserOptions;
/**
* Parser options for javascript modules.
*/
"javascript/auto"?: JavascriptParserOptions;
/**
* Parser options for javascript modules.
*/
"javascript/dynamic"?: JavascriptParserOptions;
/**
* Parser options for javascript modules.
*/
"javascript/esm"?: JavascriptParserOptions;
};
/**
* An array of rules applied for modules.
*/
@ -6238,7 +6461,7 @@ declare class OriginalSource extends Source {
*/
declare interface Output {
/**
* The filename of asset modules as relative path inside the `output.path` directory.
* The filename of asset modules as relative path inside the 'output.path' directory.
*/
assetModuleFilename?:
| string
@ -6255,7 +6478,7 @@ declare interface Output {
charset?: boolean;
/**
* The filename of non-initial chunks as relative path inside the `output.path` directory.
* Specifies the filename template of output files of non-initial chunks on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
chunkFilename?:
| string
@ -6327,7 +6550,7 @@ declare interface Output {
environment?: Environment;
/**
* Specifies the name of each output file on disk. You must **not** specify an absolute path here! The `output.path` option determines the location on disk the files are written to, filename is used solely for naming the individual files.
* Specifies the filename of output files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
filename?: string | ((pathData: PathData, assetInfo?: AssetInfo) => string);
@ -6367,7 +6590,7 @@ declare interface Output {
hotUpdateGlobal?: string;
/**
* The filename of the Hot Update Main File. It is inside the `output.path` directory.
* The filename of the Hot Update Main File. It is inside the 'output.path' directory.
*/
hotUpdateMainFilename?: string;
@ -6427,7 +6650,7 @@ declare interface Output {
scriptType?: false | "module" | "text/javascript";
/**
* The filename of the SourceMaps for the JavaScript files. They are inside the `output.path` directory.
* The filename of the SourceMaps for the JavaScript files. They are inside the 'output.path' directory.
*/
sourceMapFilename?: string;
@ -6457,7 +6680,7 @@ declare interface Output {
wasmLoading?: string | false;
/**
* The filename of WebAssembly modules as relative path inside the `output.path` directory.
* The filename of WebAssembly modules as relative path inside the 'output.path' directory.
*/
webassemblyModuleFilename?: string;
@ -6496,7 +6719,7 @@ declare interface OutputFileSystem {
*/
declare interface OutputNormalized {
/**
* The filename of asset modules as relative path inside the `output.path` directory.
* The filename of asset modules as relative path inside the 'output.path' directory.
*/
assetModuleFilename?:
| string
@ -6508,7 +6731,7 @@ declare interface OutputNormalized {
charset?: boolean;
/**
* The filename of non-initial chunks as relative path inside the `output.path` directory.
* Specifies the filename template of output files of non-initial chunks on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
chunkFilename?:
| string
@ -6580,7 +6803,7 @@ declare interface OutputNormalized {
environment?: Environment;
/**
* Specifies the name of each output file on disk. You must **not** specify an absolute path here! The `output.path` option determines the location on disk the files are written to, filename is used solely for naming the individual files.
* Specifies the filename of output files on disk. You must **not** specify an absolute path here, but the path may contain folders separated by '/'! The specified path is joined with the value of the 'output.path' option to determine the location on disk.
*/
filename?: string | ((pathData: PathData, assetInfo?: AssetInfo) => string);
@ -6620,7 +6843,7 @@ declare interface OutputNormalized {
hotUpdateGlobal?: string;
/**
* The filename of the Hot Update Main File. It is inside the `output.path` directory.
* The filename of the Hot Update Main File. It is inside the 'output.path' directory.
*/
hotUpdateMainFilename?: string;
@ -6670,7 +6893,7 @@ declare interface OutputNormalized {
scriptType?: false | "module" | "text/javascript";
/**
* The filename of the SourceMaps for the JavaScript files. They are inside the `output.path` directory.
* The filename of the SourceMaps for the JavaScript files. They are inside the 'output.path' directory.
*/
sourceMapFilename?: string;
@ -6695,7 +6918,7 @@ declare interface OutputNormalized {
wasmLoading?: string | false;
/**
* The filename of WebAssembly modules as relative path inside the `output.path` directory.
* The filename of WebAssembly modules as relative path inside the 'output.path' directory.
*/
webassemblyModuleFilename?: string;

View File

@ -6271,7 +6271,6 @@ toml@^3.0.0:
tooling@webpack/tooling#v1.12.1:
version "1.12.1"
uid "277e4514abca9af9514a0f7f2fba8b7a5609ff76"
resolved "https://codeload.github.com/webpack/tooling/tar.gz/277e4514abca9af9514a0f7f2fba8b7a5609ff76"
dependencies:
"@yarnpkg/lockfile" "^1.1.0"