feat: refactoring project
This commit is contained in:
29
node_modules/webpack/lib/config/browserslistTargetHandler.js
generated
vendored
29
node_modules/webpack/lib/config/browserslistTargetHandler.js
generated
vendored
@@ -57,14 +57,14 @@ const load = (input, context) => {
|
||||
// if a query is specified, then use it, else
|
||||
// if a path to a config is specified then load it, else
|
||||
// find a nearest config
|
||||
const config = query
|
||||
? query
|
||||
: configPath
|
||||
const config =
|
||||
query ||
|
||||
(configPath
|
||||
? browserslist.loadConfig({
|
||||
config: configPath,
|
||||
env
|
||||
})
|
||||
: browserslist.loadConfig({ path: context, env });
|
||||
: browserslist.loadConfig({ path: context, env }));
|
||||
|
||||
if (!config) return;
|
||||
return browserslist(config);
|
||||
@@ -80,8 +80,8 @@ const resolve = browsers => {
|
||||
* @param {Record<string, number | [number, number]>} versions first supported version
|
||||
* @returns {boolean} true if supports
|
||||
*/
|
||||
const rawChecker = versions => {
|
||||
return browsers.every(v => {
|
||||
const rawChecker = versions =>
|
||||
browsers.every(v => {
|
||||
const [name, parsedVersion] = v.split(" ");
|
||||
if (!name) return false;
|
||||
const requiredVersion = versions[name];
|
||||
@@ -94,19 +94,19 @@ const resolve = browsers => {
|
||||
? parsedVersion.split("-")[0].split(".")
|
||||
: parsedVersion.split(".");
|
||||
if (typeof requiredVersion === "number") {
|
||||
return +parsedMajor >= requiredVersion;
|
||||
return Number(parsedMajor) >= requiredVersion;
|
||||
}
|
||||
return requiredVersion[0] === +parsedMajor
|
||||
? +parserMinor >= requiredVersion[1]
|
||||
: +parsedMajor > requiredVersion[0];
|
||||
return requiredVersion[0] === Number(parsedMajor)
|
||||
? Number(parserMinor) >= requiredVersion[1]
|
||||
: Number(parsedMajor) > requiredVersion[0];
|
||||
});
|
||||
};
|
||||
const anyNode = browsers.some(b => /^node /.test(b));
|
||||
const anyNode = browsers.some(b => b.startsWith("node "));
|
||||
const anyBrowser = browsers.some(b => /^(?!node)/.test(b));
|
||||
const browserProperty = !anyBrowser ? false : anyNode ? null : true;
|
||||
const nodeProperty = !anyNode ? false : anyBrowser ? null : true;
|
||||
// Internet Explorer Mobile, Blackberry browser and Opera Mini are very old browsers, they do not support new features
|
||||
const es6DynamicImport = rawChecker({
|
||||
/* eslint-disable camelcase */
|
||||
chrome: 63,
|
||||
and_chr: 63,
|
||||
edge: 79,
|
||||
@@ -124,9 +124,11 @@ const resolve = browsers => {
|
||||
and_uc: [15, 5],
|
||||
kaios: [3, 0],
|
||||
node: [12, 17]
|
||||
/* eslint-enable camelcase */
|
||||
});
|
||||
|
||||
return {
|
||||
/* eslint-disable camelcase */
|
||||
const: rawChecker({
|
||||
chrome: 49,
|
||||
and_chr: 49,
|
||||
@@ -331,6 +333,7 @@ const resolve = browsers => {
|
||||
kaios: 3,
|
||||
node: [7, 6]
|
||||
}),
|
||||
/* eslint-enable camelcase */
|
||||
browser: browserProperty,
|
||||
electron: false,
|
||||
node: nodeProperty,
|
||||
@@ -346,7 +349,7 @@ const resolve = browsers => {
|
||||
nodeBuiltins: nodeProperty,
|
||||
nodePrefixForCoreModules:
|
||||
nodeProperty &&
|
||||
!browsers.some(b => /^node 15/.test(b)) &&
|
||||
!browsers.some(b => b.startsWith("node 15")) &&
|
||||
rawChecker({
|
||||
node: [14, 18]
|
||||
}),
|
||||
|
||||
464
node_modules/webpack/lib/config/defaults.js
generated
vendored
464
node_modules/webpack/lib/config/defaults.js
generated
vendored
@@ -9,15 +9,18 @@ const fs = require("fs");
|
||||
const path = require("path");
|
||||
const {
|
||||
JAVASCRIPT_MODULE_TYPE_AUTO,
|
||||
JSON_MODULE_TYPE,
|
||||
WEBASSEMBLY_MODULE_TYPE_ASYNC,
|
||||
JAVASCRIPT_MODULE_TYPE_ESM,
|
||||
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
||||
JSON_MODULE_TYPE,
|
||||
WEBASSEMBLY_MODULE_TYPE_ASYNC,
|
||||
WEBASSEMBLY_MODULE_TYPE_SYNC,
|
||||
ASSET_MODULE_TYPE,
|
||||
ASSET_MODULE_TYPE_INLINE,
|
||||
ASSET_MODULE_TYPE_RESOURCE,
|
||||
CSS_MODULE_TYPE_AUTO,
|
||||
CSS_MODULE_TYPE,
|
||||
CSS_MODULE_TYPE_MODULE
|
||||
CSS_MODULE_TYPE_MODULE,
|
||||
CSS_MODULE_TYPE_GLOBAL
|
||||
} = require("../ModuleTypeConstants");
|
||||
const Template = require("../Template");
|
||||
const { cleverMerge } = require("../util/cleverMerge");
|
||||
@@ -123,8 +126,8 @@ const A = (obj, prop, factory) => {
|
||||
if (value === undefined) {
|
||||
obj[prop] = factory();
|
||||
} else if (Array.isArray(value)) {
|
||||
/** @type {any[] | undefined} */
|
||||
let newArray = undefined;
|
||||
/** @type {EXPECTED_ANY[] | undefined} */
|
||||
let newArray;
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const item = value[i];
|
||||
if (item === "...") {
|
||||
@@ -132,7 +135,9 @@ const A = (obj, prop, factory) => {
|
||||
newArray = value.slice(0, i);
|
||||
obj[prop] = /** @type {T[P]} */ (/** @type {unknown} */ (newArray));
|
||||
}
|
||||
const items = /** @type {any[]} */ (/** @type {unknown} */ (factory()));
|
||||
const items = /** @type {EXPECTED_ANY[]} */ (
|
||||
/** @type {unknown} */ (factory())
|
||||
);
|
||||
if (items !== undefined) {
|
||||
for (const item of items) {
|
||||
newArray.push(item);
|
||||
@@ -161,13 +166,13 @@ const applyWebpackOptionsBaseDefaults = options => {
|
||||
*/
|
||||
const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
||||
F(options, "context", () => process.cwd());
|
||||
F(options, "target", () => {
|
||||
return getDefaultTarget(/** @type {string} */ (options.context));
|
||||
});
|
||||
F(options, "target", () =>
|
||||
getDefaultTarget(/** @type {string} */ (options.context))
|
||||
);
|
||||
|
||||
const { mode, name, target } = options;
|
||||
|
||||
let targetProperties =
|
||||
const targetProperties =
|
||||
target === false
|
||||
? /** @type {false} */ (false)
|
||||
: typeof target === "string"
|
||||
@@ -217,7 +222,7 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
||||
cacheUnaffected: options.experiments.cacheUnaffected,
|
||||
compilerIndex
|
||||
});
|
||||
const cache = !!options.cache;
|
||||
const cache = Boolean(options.cache);
|
||||
|
||||
applySnapshotDefaults(options.snapshot, {
|
||||
production,
|
||||
@@ -258,7 +263,7 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
||||
|
||||
applyExternalsPresetsDefaults(options.externalsPresets, {
|
||||
targetProperties,
|
||||
buildHttp: !!options.experiments.buildHttp
|
||||
buildHttp: Boolean(options.experiments.buildHttp)
|
||||
});
|
||||
|
||||
applyLoaderDefaults(
|
||||
@@ -275,7 +280,7 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
||||
validExternalTypes.includes(options.output.library.type)
|
||||
? /** @type {ExternalsType} */ (options.output.library.type)
|
||||
: options.output.module
|
||||
? "module"
|
||||
? "module-import"
|
||||
: "var";
|
||||
});
|
||||
|
||||
@@ -283,7 +288,9 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
||||
futureDefaults:
|
||||
/** @type {NonNullable<WebpackOptionsNormalized["experiments"]["futureDefaults"]>} */
|
||||
(options.experiments.futureDefaults),
|
||||
outputModule: options.output.module,
|
||||
outputModule:
|
||||
/** @type {NonNullable<WebpackOptionsNormalized["output"]["module"]>} */
|
||||
(options.output.module),
|
||||
targetProperties
|
||||
});
|
||||
|
||||
@@ -308,7 +315,7 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
||||
css:
|
||||
/** @type {NonNullable<ExperimentsNormalized["css"]>} */
|
||||
(options.experiments.css),
|
||||
records: !!(options.recordsInputPath || options.recordsOutputPath)
|
||||
records: Boolean(options.recordsInputPath || options.recordsOutputPath)
|
||||
});
|
||||
|
||||
options.resolve = cleverMerge(
|
||||
@@ -399,8 +406,8 @@ const applyCacheDefaults = (
|
||||
case "filesystem":
|
||||
F(cache, "name", () =>
|
||||
compilerIndex !== undefined
|
||||
? `${name + "-" + mode}__compiler${compilerIndex + 1}__`
|
||||
: name + "-" + mode
|
||||
? `${`${name}-${mode}`}__compiler${compilerIndex + 1}__`
|
||||
: `${name}-${mode}`
|
||||
);
|
||||
D(cache, "version", "");
|
||||
F(cache, "cacheDirectory", () => {
|
||||
@@ -411,7 +418,7 @@ const applyCacheDefaults = (
|
||||
try {
|
||||
if (fs.statSync(path.join(dir, "package.json")).isFile()) break;
|
||||
// eslint-disable-next-line no-empty
|
||||
} catch (e) {}
|
||||
} catch (_err) {}
|
||||
const parent = path.dirname(dir);
|
||||
if (dir === parent) {
|
||||
dir = undefined;
|
||||
@@ -425,9 +432,8 @@ const applyCacheDefaults = (
|
||||
return path.resolve(dir, ".pnp/.cache/webpack");
|
||||
} else if (process.versions.pnp === "3") {
|
||||
return path.resolve(dir, ".yarn/.cache/webpack");
|
||||
} else {
|
||||
return path.resolve(dir, "node_modules/.cache/webpack");
|
||||
}
|
||||
return path.resolve(dir, "node_modules/.cache/webpack");
|
||||
});
|
||||
F(cache, "cacheLocation", () =>
|
||||
path.resolve(
|
||||
@@ -632,19 +638,19 @@ const applyModuleDefaults = (
|
||||
F(module.parser, ASSET_MODULE_TYPE, () => ({}));
|
||||
F(
|
||||
/** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
|
||||
(module.parser.asset),
|
||||
(module.parser[ASSET_MODULE_TYPE]),
|
||||
"dataUrlCondition",
|
||||
() => ({})
|
||||
);
|
||||
if (
|
||||
typeof (
|
||||
/** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
|
||||
(module.parser.asset).dataUrlCondition
|
||||
(module.parser[ASSET_MODULE_TYPE]).dataUrlCondition
|
||||
) === "object"
|
||||
) {
|
||||
D(
|
||||
/** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
|
||||
(module.parser.asset).dataUrlCondition,
|
||||
(module.parser[ASSET_MODULE_TYPE]).dataUrlCondition,
|
||||
"maxSize",
|
||||
8096
|
||||
);
|
||||
@@ -662,41 +668,41 @@ const applyModuleDefaults = (
|
||||
);
|
||||
|
||||
if (css) {
|
||||
F(module.parser, "css", () => ({}));
|
||||
F(module.parser, CSS_MODULE_TYPE, () => ({}));
|
||||
|
||||
D(module.parser.css, "namedExports", true);
|
||||
D(module.parser[CSS_MODULE_TYPE], "namedExports", true);
|
||||
|
||||
F(module.generator, "css", () => ({}));
|
||||
F(module.generator, CSS_MODULE_TYPE, () => ({}));
|
||||
|
||||
applyCssGeneratorOptionsDefaults(
|
||||
/** @type {NonNullable<GeneratorOptionsByModuleTypeKnown["css"]>} */
|
||||
(module.generator.css),
|
||||
(module.generator[CSS_MODULE_TYPE]),
|
||||
{ targetProperties }
|
||||
);
|
||||
|
||||
F(module.generator, "css/auto", () => ({}));
|
||||
F(module.generator, CSS_MODULE_TYPE_AUTO, () => ({}));
|
||||
D(
|
||||
module.generator["css/auto"],
|
||||
module.generator[CSS_MODULE_TYPE_AUTO],
|
||||
"localIdentName",
|
||||
"[uniqueName]-[id]-[local]"
|
||||
);
|
||||
D(module.generator["css/auto"], "exportsConvention", "as-is");
|
||||
D(module.generator[CSS_MODULE_TYPE_AUTO], "exportsConvention", "as-is");
|
||||
|
||||
F(module.generator, "css/module", () => ({}));
|
||||
F(module.generator, CSS_MODULE_TYPE_MODULE, () => ({}));
|
||||
D(
|
||||
module.generator["css/module"],
|
||||
module.generator[CSS_MODULE_TYPE_MODULE],
|
||||
"localIdentName",
|
||||
"[uniqueName]-[id]-[local]"
|
||||
);
|
||||
D(module.generator["css/module"], "exportsConvention", "as-is");
|
||||
D(module.generator[CSS_MODULE_TYPE_MODULE], "exportsConvention", "as-is");
|
||||
|
||||
F(module.generator, "css/global", () => ({}));
|
||||
F(module.generator, CSS_MODULE_TYPE_GLOBAL, () => ({}));
|
||||
D(
|
||||
module.generator["css/global"],
|
||||
module.generator[CSS_MODULE_TYPE_GLOBAL],
|
||||
"localIdentName",
|
||||
"[uniqueName]-[id]-[local]"
|
||||
);
|
||||
D(module.generator["css/global"], "exportsConvention", "as-is");
|
||||
D(module.generator[CSS_MODULE_TYPE_GLOBAL], "exportsConvention", "as-is");
|
||||
}
|
||||
|
||||
A(module, "defaultRules", () => {
|
||||
@@ -828,19 +834,19 @@ const applyModuleDefaults = (
|
||||
oneOf: [
|
||||
{
|
||||
scheme: /^data$/,
|
||||
type: "asset/inline"
|
||||
type: ASSET_MODULE_TYPE_INLINE
|
||||
},
|
||||
{
|
||||
type: "asset/resource"
|
||||
type: ASSET_MODULE_TYPE_RESOURCE
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
assert: { type: "json" },
|
||||
assert: { type: JSON_MODULE_TYPE },
|
||||
type: JSON_MODULE_TYPE
|
||||
},
|
||||
{
|
||||
with: { type: "json" },
|
||||
with: { type: JSON_MODULE_TYPE },
|
||||
type: JSON_MODULE_TYPE
|
||||
}
|
||||
);
|
||||
@@ -909,196 +915,18 @@ const applyOutputDefaults = (
|
||||
try {
|
||||
const packageInfo = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
||||
return packageInfo.name || "";
|
||||
} catch (e) {
|
||||
if (/** @type {Error & { code: string }} */ (e).code !== "ENOENT") {
|
||||
} catch (err) {
|
||||
if (/** @type {Error & { code: string }} */ (err).code !== "ENOENT") {
|
||||
/** @type {Error & { code: string }} */
|
||||
(e).message +=
|
||||
(err).message +=
|
||||
`\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`;
|
||||
throw e;
|
||||
throw err;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
F(output, "module", () => !!outputModule);
|
||||
D(output, "filename", output.module ? "[name].mjs" : "[name].js");
|
||||
F(output, "iife", () => !output.module);
|
||||
D(output, "importFunctionName", "import");
|
||||
D(output, "importMetaName", "import.meta");
|
||||
F(output, "chunkFilename", () => {
|
||||
const filename =
|
||||
/** @type {NonNullable<Output["chunkFilename"]>} */
|
||||
(output.filename);
|
||||
if (typeof filename !== "function") {
|
||||
const hasName = filename.includes("[name]");
|
||||
const hasId = filename.includes("[id]");
|
||||
const hasChunkHash = filename.includes("[chunkhash]");
|
||||
const hasContentHash = filename.includes("[contenthash]");
|
||||
// Anything changing depending on chunk is fine
|
||||
if (hasChunkHash || hasContentHash || hasName || hasId) return filename;
|
||||
// Otherwise prefix "[id]." in front of the basename to make it changing
|
||||
return filename.replace(/(^|\/)([^/]*(?:\?|$))/, "$1[id].$2");
|
||||
}
|
||||
return output.module ? "[id].mjs" : "[id].js";
|
||||
});
|
||||
F(output, "cssFilename", () => {
|
||||
const filename =
|
||||
/** @type {NonNullable<Output["cssFilename"]>} */
|
||||
(output.filename);
|
||||
if (typeof filename !== "function") {
|
||||
return filename.replace(/\.[mc]?js(\?|$)/, ".css$1");
|
||||
}
|
||||
return "[id].css";
|
||||
});
|
||||
F(output, "cssChunkFilename", () => {
|
||||
const chunkFilename =
|
||||
/** @type {NonNullable<Output["cssChunkFilename"]>} */
|
||||
(output.chunkFilename);
|
||||
if (typeof chunkFilename !== "function") {
|
||||
return chunkFilename.replace(/\.[mc]?js(\?|$)/, ".css$1");
|
||||
}
|
||||
return "[id].css";
|
||||
});
|
||||
D(output, "cssHeadDataCompression", !development);
|
||||
D(output, "assetModuleFilename", "[hash][ext][query]");
|
||||
D(output, "webassemblyModuleFilename", "[hash].module.wasm");
|
||||
D(output, "compareBeforeEmit", true);
|
||||
D(output, "charset", true);
|
||||
const uniqueNameId = Template.toIdentifier(
|
||||
/** @type {NonNullable<Output["uniqueName"]>} */ (output.uniqueName)
|
||||
);
|
||||
F(output, "hotUpdateGlobal", () => "webpackHotUpdate" + uniqueNameId);
|
||||
F(output, "chunkLoadingGlobal", () => "webpackChunk" + uniqueNameId);
|
||||
F(output, "globalObject", () => {
|
||||
if (tp) {
|
||||
if (tp.global) return "global";
|
||||
if (tp.globalThis) return "globalThis";
|
||||
}
|
||||
return "self";
|
||||
});
|
||||
F(output, "chunkFormat", () => {
|
||||
if (tp) {
|
||||
const helpMessage = isAffectedByBrowserslist
|
||||
? "Make sure that your 'browserslist' includes only platforms that support these features or select an appropriate 'target' to allow selecting a chunk format by default. Alternatively specify the 'output.chunkFormat' directly."
|
||||
: "Select an appropriate 'target' to allow selecting one by default, or specify the 'output.chunkFormat' directly.";
|
||||
if (output.module) {
|
||||
if (tp.dynamicImport) return "module";
|
||||
if (tp.document) return "array-push";
|
||||
throw new Error(
|
||||
"For the selected environment is no default ESM chunk format available:\n" +
|
||||
"ESM exports can be chosen when 'import()' is available.\n" +
|
||||
"JSONP Array push can be chosen when 'document' is available.\n" +
|
||||
helpMessage
|
||||
);
|
||||
} else {
|
||||
if (tp.document) return "array-push";
|
||||
if (tp.require) return "commonjs";
|
||||
if (tp.nodeBuiltins) return "commonjs";
|
||||
if (tp.importScripts) return "array-push";
|
||||
throw new Error(
|
||||
"For the selected environment is no default script chunk format available:\n" +
|
||||
"JSONP Array push can be chosen when 'document' or 'importScripts' is available.\n" +
|
||||
"CommonJs exports can be chosen when 'require' or node builtins are available.\n" +
|
||||
helpMessage
|
||||
);
|
||||
}
|
||||
}
|
||||
throw new Error(
|
||||
"Chunk format can't be selected by default when no target is specified"
|
||||
);
|
||||
});
|
||||
D(output, "asyncChunks", true);
|
||||
F(output, "chunkLoading", () => {
|
||||
if (tp) {
|
||||
switch (output.chunkFormat) {
|
||||
case "array-push":
|
||||
if (tp.document) return "jsonp";
|
||||
if (tp.importScripts) return "import-scripts";
|
||||
break;
|
||||
case "commonjs":
|
||||
if (tp.require) return "require";
|
||||
if (tp.nodeBuiltins) return "async-node";
|
||||
break;
|
||||
case "module":
|
||||
if (tp.dynamicImport || output.module) return "import";
|
||||
break;
|
||||
}
|
||||
if (
|
||||
tp.require === null ||
|
||||
tp.nodeBuiltins === null ||
|
||||
tp.document === null ||
|
||||
tp.importScripts === null
|
||||
) {
|
||||
return "universal";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
F(output, "workerChunkLoading", () => {
|
||||
if (tp) {
|
||||
switch (output.chunkFormat) {
|
||||
case "array-push":
|
||||
if (tp.importScriptsInWorker) return "import-scripts";
|
||||
break;
|
||||
case "commonjs":
|
||||
if (tp.require) return "require";
|
||||
if (tp.nodeBuiltins) return "async-node";
|
||||
break;
|
||||
case "module":
|
||||
if (tp.dynamicImportInWorker || output.module) return "import";
|
||||
break;
|
||||
}
|
||||
if (
|
||||
tp.require === null ||
|
||||
tp.nodeBuiltins === null ||
|
||||
tp.importScriptsInWorker === null
|
||||
) {
|
||||
return "universal";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
F(output, "wasmLoading", () => {
|
||||
if (tp) {
|
||||
if (tp.fetchWasm) return "fetch";
|
||||
if (tp.nodeBuiltins)
|
||||
return output.module ? "async-node-module" : "async-node";
|
||||
if (tp.nodeBuiltins === null || tp.fetchWasm === null) {
|
||||
return "universal";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
F(output, "workerWasmLoading", () => output.wasmLoading);
|
||||
F(output, "devtoolNamespace", () => output.uniqueName);
|
||||
if (output.library) {
|
||||
F(output.library, "type", () => (output.module ? "module" : "var"));
|
||||
}
|
||||
F(output, "path", () => path.join(process.cwd(), "dist"));
|
||||
F(output, "pathinfo", () => development);
|
||||
D(output, "sourceMapFilename", "[file].map[query]");
|
||||
D(
|
||||
output,
|
||||
"hotUpdateChunkFilename",
|
||||
`[id].[fullhash].hot-update.${output.module ? "mjs" : "js"}`
|
||||
);
|
||||
D(output, "hotUpdateMainFilename", "[runtime].[fullhash].hot-update.json");
|
||||
D(output, "crossOriginLoading", false);
|
||||
F(output, "scriptType", () => (output.module ? "module" : false));
|
||||
D(
|
||||
output,
|
||||
"publicPath",
|
||||
(tp && (tp.document || tp.importScripts)) || output.scriptType === "module"
|
||||
? "auto"
|
||||
: ""
|
||||
);
|
||||
D(output, "workerPublicPath", "");
|
||||
D(output, "chunkLoadTimeout", 120000);
|
||||
D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
|
||||
D(output, "hashDigest", "hex");
|
||||
D(output, "hashDigestLength", futureDefaults ? 16 : 20);
|
||||
D(output, "strictModuleErrorHandling", false);
|
||||
D(output, "strictModuleExceptionHandling", false);
|
||||
F(output, "module", () => Boolean(outputModule));
|
||||
|
||||
const environment = /** @type {Environment} */ (output.environment);
|
||||
/**
|
||||
@@ -1121,7 +949,8 @@ const applyOutputDefaults = (
|
||||
F(
|
||||
environment,
|
||||
"bigIntLiteral",
|
||||
() => /** @type {boolean | undefined} */ (tp && tp.bigIntLiteral)
|
||||
() =>
|
||||
tp && optimistic(/** @type {boolean | undefined} */ (tp.bigIntLiteral))
|
||||
);
|
||||
F(
|
||||
environment,
|
||||
@@ -1196,6 +1025,187 @@ const applyOutputDefaults = (
|
||||
() => tp && optimistic(/** @type {boolean | undefined} */ (tp.document))
|
||||
);
|
||||
|
||||
D(output, "filename", output.module ? "[name].mjs" : "[name].js");
|
||||
F(output, "iife", () => !output.module);
|
||||
D(output, "importFunctionName", "import");
|
||||
D(output, "importMetaName", "import.meta");
|
||||
F(output, "chunkFilename", () => {
|
||||
const filename =
|
||||
/** @type {NonNullable<Output["chunkFilename"]>} */
|
||||
(output.filename);
|
||||
if (typeof filename !== "function") {
|
||||
const hasName = filename.includes("[name]");
|
||||
const hasId = filename.includes("[id]");
|
||||
const hasChunkHash = filename.includes("[chunkhash]");
|
||||
const hasContentHash = filename.includes("[contenthash]");
|
||||
// Anything changing depending on chunk is fine
|
||||
if (hasChunkHash || hasContentHash || hasName || hasId) return filename;
|
||||
// Otherwise prefix "[id]." in front of the basename to make it changing
|
||||
return filename.replace(/(^|\/)([^/]*(?:\?|$))/, "$1[id].$2");
|
||||
}
|
||||
return output.module ? "[id].mjs" : "[id].js";
|
||||
});
|
||||
F(output, "cssFilename", () => {
|
||||
const filename =
|
||||
/** @type {NonNullable<Output["cssFilename"]>} */
|
||||
(output.filename);
|
||||
if (typeof filename !== "function") {
|
||||
return filename.replace(/\.[mc]?js(\?|$)/, ".css$1");
|
||||
}
|
||||
return "[id].css";
|
||||
});
|
||||
F(output, "cssChunkFilename", () => {
|
||||
const chunkFilename =
|
||||
/** @type {NonNullable<Output["cssChunkFilename"]>} */
|
||||
(output.chunkFilename);
|
||||
if (typeof chunkFilename !== "function") {
|
||||
return chunkFilename.replace(/\.[mc]?js(\?|$)/, ".css$1");
|
||||
}
|
||||
return "[id].css";
|
||||
});
|
||||
D(output, "cssHeadDataCompression", !development);
|
||||
D(output, "assetModuleFilename", "[hash][ext][query]");
|
||||
D(output, "webassemblyModuleFilename", "[hash].module.wasm");
|
||||
D(output, "compareBeforeEmit", true);
|
||||
D(output, "charset", true);
|
||||
const uniqueNameId = Template.toIdentifier(
|
||||
/** @type {NonNullable<Output["uniqueName"]>} */ (output.uniqueName)
|
||||
);
|
||||
F(output, "hotUpdateGlobal", () => `webpackHotUpdate${uniqueNameId}`);
|
||||
F(output, "chunkLoadingGlobal", () => `webpackChunk${uniqueNameId}`);
|
||||
F(output, "globalObject", () => {
|
||||
if (tp) {
|
||||
if (tp.global) return "global";
|
||||
if (tp.globalThis) return "globalThis";
|
||||
}
|
||||
return "self";
|
||||
});
|
||||
F(output, "chunkFormat", () => {
|
||||
if (tp) {
|
||||
const helpMessage = isAffectedByBrowserslist
|
||||
? "Make sure that your 'browserslist' includes only platforms that support these features or select an appropriate 'target' to allow selecting a chunk format by default. Alternatively specify the 'output.chunkFormat' directly."
|
||||
: "Select an appropriate 'target' to allow selecting one by default, or specify the 'output.chunkFormat' directly.";
|
||||
if (output.module) {
|
||||
if (environment.dynamicImport) return "module";
|
||||
if (tp.document) return "array-push";
|
||||
throw new Error(
|
||||
"For the selected environment is no default ESM chunk format available:\n" +
|
||||
"ESM exports can be chosen when 'import()' is available.\n" +
|
||||
`JSONP Array push can be chosen when 'document' is available.\n${
|
||||
helpMessage
|
||||
}`
|
||||
);
|
||||
} else {
|
||||
if (tp.document) return "array-push";
|
||||
if (tp.require) return "commonjs";
|
||||
if (tp.nodeBuiltins) return "commonjs";
|
||||
if (tp.importScripts) return "array-push";
|
||||
throw new Error(
|
||||
"For the selected environment is no default script chunk format available:\n" +
|
||||
"JSONP Array push can be chosen when 'document' or 'importScripts' is available.\n" +
|
||||
`CommonJs exports can be chosen when 'require' or node builtins are available.\n${
|
||||
helpMessage
|
||||
}`
|
||||
);
|
||||
}
|
||||
}
|
||||
throw new Error(
|
||||
"Chunk format can't be selected by default when no target is specified"
|
||||
);
|
||||
});
|
||||
D(output, "asyncChunks", true);
|
||||
F(output, "chunkLoading", () => {
|
||||
if (tp) {
|
||||
switch (output.chunkFormat) {
|
||||
case "array-push":
|
||||
if (tp.document) return "jsonp";
|
||||
if (tp.importScripts) return "import-scripts";
|
||||
break;
|
||||
case "commonjs":
|
||||
if (tp.require) return "require";
|
||||
if (tp.nodeBuiltins) return "async-node";
|
||||
break;
|
||||
case "module":
|
||||
if (environment.dynamicImport) return "import";
|
||||
break;
|
||||
}
|
||||
if (
|
||||
tp.require === null ||
|
||||
tp.nodeBuiltins === null ||
|
||||
tp.document === null ||
|
||||
tp.importScripts === null
|
||||
) {
|
||||
return "universal";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
F(output, "workerChunkLoading", () => {
|
||||
if (tp) {
|
||||
switch (output.chunkFormat) {
|
||||
case "array-push":
|
||||
if (tp.importScriptsInWorker) return "import-scripts";
|
||||
break;
|
||||
case "commonjs":
|
||||
if (tp.require) return "require";
|
||||
if (tp.nodeBuiltins) return "async-node";
|
||||
break;
|
||||
case "module":
|
||||
if (environment.dynamicImportInWorker) return "import";
|
||||
break;
|
||||
}
|
||||
if (
|
||||
tp.require === null ||
|
||||
tp.nodeBuiltins === null ||
|
||||
tp.importScriptsInWorker === null
|
||||
) {
|
||||
return "universal";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
F(output, "wasmLoading", () => {
|
||||
if (tp) {
|
||||
if (tp.fetchWasm) return "fetch";
|
||||
if (tp.nodeBuiltins)
|
||||
return output.module ? "async-node-module" : "async-node";
|
||||
if (tp.nodeBuiltins === null || tp.fetchWasm === null) {
|
||||
return "universal";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
F(output, "workerWasmLoading", () => output.wasmLoading);
|
||||
F(output, "devtoolNamespace", () => output.uniqueName);
|
||||
if (output.library) {
|
||||
F(output.library, "type", () => (output.module ? "module" : "var"));
|
||||
}
|
||||
F(output, "path", () => path.join(process.cwd(), "dist"));
|
||||
F(output, "pathinfo", () => development);
|
||||
D(output, "sourceMapFilename", "[file].map[query]");
|
||||
D(
|
||||
output,
|
||||
"hotUpdateChunkFilename",
|
||||
`[id].[fullhash].hot-update.${output.module ? "mjs" : "js"}`
|
||||
);
|
||||
D(output, "hotUpdateMainFilename", "[runtime].[fullhash].hot-update.json");
|
||||
D(output, "crossOriginLoading", false);
|
||||
F(output, "scriptType", () => (output.module ? "module" : false));
|
||||
D(
|
||||
output,
|
||||
"publicPath",
|
||||
(tp && (tp.document || tp.importScripts)) || output.scriptType === "module"
|
||||
? "auto"
|
||||
: ""
|
||||
);
|
||||
D(output, "workerPublicPath", "");
|
||||
D(output, "chunkLoadTimeout", 120000);
|
||||
D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
|
||||
D(output, "hashDigest", "hex");
|
||||
D(output, "hashDigestLength", futureDefaults ? 16 : 20);
|
||||
D(output, "strictModuleErrorHandling", false);
|
||||
D(output, "strictModuleExceptionHandling", false);
|
||||
|
||||
const { trustedTypes } = output;
|
||||
if (trustedTypes) {
|
||||
F(
|
||||
@@ -1432,6 +1442,7 @@ const applyOptimizationDefaults = (
|
||||
D(optimization, "innerGraph", production);
|
||||
D(optimization, "mangleExports", production);
|
||||
D(optimization, "concatenateModules", production);
|
||||
D(optimization, "avoidEntryIife", production);
|
||||
D(optimization, "runtimeChunk", false);
|
||||
D(optimization, "emitOnErrors", !production);
|
||||
D(optimization, "checkWasmTypes", production);
|
||||
@@ -1632,5 +1643,6 @@ const applyInfrastructureLoggingDefaults = infrastructureLogging => {
|
||||
D(infrastructureLogging, "appendOnly", !tty);
|
||||
};
|
||||
|
||||
exports.applyWebpackOptionsBaseDefaults = applyWebpackOptionsBaseDefaults;
|
||||
exports.applyWebpackOptionsDefaults = applyWebpackOptionsDefaults;
|
||||
module.exports.applyWebpackOptionsBaseDefaults =
|
||||
applyWebpackOptionsBaseDefaults;
|
||||
module.exports.applyWebpackOptionsDefaults = applyWebpackOptionsDefaults;
|
||||
|
||||
683
node_modules/webpack/lib/config/normalization.js
generated
vendored
683
node_modules/webpack/lib/config/normalization.js
generated
vendored
@@ -56,10 +56,7 @@ const nestedConfig = (value, fn) =>
|
||||
* @param {T|undefined} value value or not
|
||||
* @returns {T} result value
|
||||
*/
|
||||
const cloneObject = value => {
|
||||
return /** @type {T} */ ({ ...value });
|
||||
};
|
||||
|
||||
const cloneObject = value => /** @type {T} */ ({ ...value });
|
||||
/**
|
||||
* @template T
|
||||
* @template R
|
||||
@@ -98,6 +95,7 @@ const optionalNestedArray = (value, fn) =>
|
||||
* @returns {Record<string, R>} result value
|
||||
*/
|
||||
const keyedNestedConfig = (value, fn, customKeys) => {
|
||||
/* eslint-disable no-sequences */
|
||||
const result =
|
||||
value === undefined
|
||||
? {}
|
||||
@@ -110,6 +108,7 @@ const keyedNestedConfig = (value, fn, customKeys) => {
|
||||
),
|
||||
/** @type {Record<string, R>} */ ({})
|
||||
);
|
||||
/* eslint-enable no-sequences */
|
||||
if (customKeys) {
|
||||
for (const key of Object.keys(customKeys)) {
|
||||
if (!(key in result)) {
|
||||
@@ -124,357 +123,349 @@ const keyedNestedConfig = (value, fn, customKeys) => {
|
||||
* @param {WebpackOptions} config input config
|
||||
* @returns {WebpackOptionsNormalized} normalized options
|
||||
*/
|
||||
const getNormalizedWebpackOptions = config => {
|
||||
return {
|
||||
amd: config.amd,
|
||||
bail: config.bail,
|
||||
cache:
|
||||
/** @type {NonNullable<CacheOptions>} */
|
||||
(
|
||||
optionalNestedConfig(config.cache, cache => {
|
||||
if (cache === false) return false;
|
||||
if (cache === true) {
|
||||
const getNormalizedWebpackOptions = config => ({
|
||||
amd: config.amd,
|
||||
bail: config.bail,
|
||||
cache:
|
||||
/** @type {NonNullable<CacheOptions>} */
|
||||
(
|
||||
optionalNestedConfig(config.cache, cache => {
|
||||
if (cache === false) return false;
|
||||
if (cache === true) {
|
||||
return {
|
||||
type: "memory",
|
||||
maxGenerations: undefined
|
||||
};
|
||||
}
|
||||
switch (cache.type) {
|
||||
case "filesystem":
|
||||
return {
|
||||
type: "filesystem",
|
||||
allowCollectingMemory: cache.allowCollectingMemory,
|
||||
maxMemoryGenerations: cache.maxMemoryGenerations,
|
||||
maxAge: cache.maxAge,
|
||||
profile: cache.profile,
|
||||
buildDependencies: cloneObject(cache.buildDependencies),
|
||||
cacheDirectory: cache.cacheDirectory,
|
||||
cacheLocation: cache.cacheLocation,
|
||||
hashAlgorithm: cache.hashAlgorithm,
|
||||
compression: cache.compression,
|
||||
idleTimeout: cache.idleTimeout,
|
||||
idleTimeoutForInitialStore: cache.idleTimeoutForInitialStore,
|
||||
idleTimeoutAfterLargeChanges: cache.idleTimeoutAfterLargeChanges,
|
||||
name: cache.name,
|
||||
store: cache.store,
|
||||
version: cache.version,
|
||||
readonly: cache.readonly
|
||||
};
|
||||
case undefined:
|
||||
case "memory":
|
||||
return {
|
||||
type: "memory",
|
||||
maxGenerations: undefined
|
||||
maxGenerations: cache.maxGenerations
|
||||
};
|
||||
default:
|
||||
// @ts-expect-error Property 'type' does not exist on type 'never'. ts(2339)
|
||||
throw new Error(`Not implemented cache.type ${cache.type}`);
|
||||
}
|
||||
})
|
||||
),
|
||||
context: config.context,
|
||||
dependencies: config.dependencies,
|
||||
devServer: optionalNestedConfig(config.devServer, devServer => {
|
||||
if (devServer === false) return false;
|
||||
return { ...devServer };
|
||||
}),
|
||||
devtool: config.devtool,
|
||||
entry:
|
||||
config.entry === undefined
|
||||
? { main: {} }
|
||||
: typeof config.entry === "function"
|
||||
? (
|
||||
fn => () =>
|
||||
Promise.resolve().then(fn).then(getNormalizedEntryStatic)
|
||||
)(config.entry)
|
||||
: getNormalizedEntryStatic(config.entry),
|
||||
experiments: nestedConfig(config.experiments, experiments => ({
|
||||
...experiments,
|
||||
buildHttp: optionalNestedConfig(experiments.buildHttp, options =>
|
||||
Array.isArray(options) ? { allowedUris: options } : options
|
||||
),
|
||||
lazyCompilation: optionalNestedConfig(
|
||||
experiments.lazyCompilation,
|
||||
options => (options === true ? {} : options)
|
||||
)
|
||||
})),
|
||||
externals: /** @type {NonNullable<Externals>} */ (config.externals),
|
||||
externalsPresets: cloneObject(config.externalsPresets),
|
||||
externalsType: config.externalsType,
|
||||
ignoreWarnings: config.ignoreWarnings
|
||||
? config.ignoreWarnings.map(ignore => {
|
||||
if (typeof ignore === "function") return ignore;
|
||||
const i = ignore instanceof RegExp ? { message: ignore } : ignore;
|
||||
return (warning, { requestShortener }) => {
|
||||
if (!i.message && !i.module && !i.file) return false;
|
||||
if (i.message && !i.message.test(warning.message)) {
|
||||
return false;
|
||||
}
|
||||
switch (cache.type) {
|
||||
case "filesystem":
|
||||
return {
|
||||
type: "filesystem",
|
||||
allowCollectingMemory: cache.allowCollectingMemory,
|
||||
maxMemoryGenerations: cache.maxMemoryGenerations,
|
||||
maxAge: cache.maxAge,
|
||||
profile: cache.profile,
|
||||
buildDependencies: cloneObject(cache.buildDependencies),
|
||||
cacheDirectory: cache.cacheDirectory,
|
||||
cacheLocation: cache.cacheLocation,
|
||||
hashAlgorithm: cache.hashAlgorithm,
|
||||
compression: cache.compression,
|
||||
idleTimeout: cache.idleTimeout,
|
||||
idleTimeoutForInitialStore: cache.idleTimeoutForInitialStore,
|
||||
idleTimeoutAfterLargeChanges:
|
||||
cache.idleTimeoutAfterLargeChanges,
|
||||
name: cache.name,
|
||||
store: cache.store,
|
||||
version: cache.version,
|
||||
readonly: cache.readonly
|
||||
};
|
||||
case undefined:
|
||||
case "memory":
|
||||
return {
|
||||
type: "memory",
|
||||
maxGenerations: cache.maxGenerations
|
||||
};
|
||||
default:
|
||||
// @ts-expect-error Property 'type' does not exist on type 'never'. ts(2339)
|
||||
throw new Error(`Not implemented cache.type ${cache.type}`);
|
||||
if (
|
||||
i.module &&
|
||||
(!warning.module ||
|
||||
!i.module.test(
|
||||
warning.module.readableIdentifier(requestShortener)
|
||||
))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
),
|
||||
context: config.context,
|
||||
dependencies: config.dependencies,
|
||||
devServer: optionalNestedConfig(config.devServer, devServer => {
|
||||
if (devServer === false) return false;
|
||||
return { ...devServer };
|
||||
}),
|
||||
devtool: config.devtool,
|
||||
entry:
|
||||
config.entry === undefined
|
||||
? { main: {} }
|
||||
: typeof config.entry === "function"
|
||||
? (
|
||||
fn => () =>
|
||||
Promise.resolve().then(fn).then(getNormalizedEntryStatic)
|
||||
)(config.entry)
|
||||
: getNormalizedEntryStatic(config.entry),
|
||||
experiments: nestedConfig(config.experiments, experiments => ({
|
||||
...experiments,
|
||||
buildHttp: optionalNestedConfig(experiments.buildHttp, options =>
|
||||
Array.isArray(options) ? { allowedUris: options } : options
|
||||
),
|
||||
lazyCompilation: optionalNestedConfig(
|
||||
experiments.lazyCompilation,
|
||||
options => (options === true ? {} : options)
|
||||
)
|
||||
})),
|
||||
externals: /** @type {NonNullable<Externals>} */ (config.externals),
|
||||
externalsPresets: cloneObject(config.externalsPresets),
|
||||
externalsType: config.externalsType,
|
||||
ignoreWarnings: config.ignoreWarnings
|
||||
? config.ignoreWarnings.map(ignore => {
|
||||
if (typeof ignore === "function") return ignore;
|
||||
const i = ignore instanceof RegExp ? { message: ignore } : ignore;
|
||||
return (warning, { requestShortener }) => {
|
||||
if (!i.message && !i.module && !i.file) return false;
|
||||
if (i.message && !i.message.test(warning.message)) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
i.module &&
|
||||
(!warning.module ||
|
||||
!i.module.test(
|
||||
warning.module.readableIdentifier(requestShortener)
|
||||
))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (i.file && (!warning.file || !i.file.test(warning.file))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
})
|
||||
: undefined,
|
||||
infrastructureLogging: cloneObject(config.infrastructureLogging),
|
||||
loader: cloneObject(config.loader),
|
||||
mode: config.mode,
|
||||
module:
|
||||
/** @type {ModuleOptionsNormalized} */
|
||||
(
|
||||
nestedConfig(config.module, module => ({
|
||||
noParse: module.noParse,
|
||||
unsafeCache: module.unsafeCache,
|
||||
parser: keyedNestedConfig(module.parser, cloneObject, {
|
||||
javascript: parserOptions => ({
|
||||
unknownContextRequest: module.unknownContextRequest,
|
||||
unknownContextRegExp: module.unknownContextRegExp,
|
||||
unknownContextRecursive: module.unknownContextRecursive,
|
||||
unknownContextCritical: module.unknownContextCritical,
|
||||
exprContextRequest: module.exprContextRequest,
|
||||
exprContextRegExp: module.exprContextRegExp,
|
||||
exprContextRecursive: module.exprContextRecursive,
|
||||
exprContextCritical: module.exprContextCritical,
|
||||
wrappedContextRegExp: module.wrappedContextRegExp,
|
||||
wrappedContextRecursive: module.wrappedContextRecursive,
|
||||
wrappedContextCritical: module.wrappedContextCritical,
|
||||
// TODO webpack 6 remove
|
||||
strictExportPresence: module.strictExportPresence,
|
||||
strictThisContextOnImports: module.strictThisContextOnImports,
|
||||
...parserOptions
|
||||
})
|
||||
}),
|
||||
generator: cloneObject(module.generator),
|
||||
defaultRules: optionalNestedArray(module.defaultRules, r => [...r]),
|
||||
rules: nestedArray(module.rules, r => [...r])
|
||||
}))
|
||||
),
|
||||
name: config.name,
|
||||
node: nestedConfig(
|
||||
config.node,
|
||||
node =>
|
||||
node && {
|
||||
...node
|
||||
if (i.file && (!warning.file || !i.file.test(warning.file))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
})
|
||||
: undefined,
|
||||
infrastructureLogging: cloneObject(config.infrastructureLogging),
|
||||
loader: cloneObject(config.loader),
|
||||
mode: config.mode,
|
||||
module:
|
||||
/** @type {ModuleOptionsNormalized} */
|
||||
(
|
||||
nestedConfig(config.module, module => ({
|
||||
noParse: module.noParse,
|
||||
unsafeCache: module.unsafeCache,
|
||||
parser: keyedNestedConfig(module.parser, cloneObject, {
|
||||
javascript: parserOptions => ({
|
||||
unknownContextRequest: module.unknownContextRequest,
|
||||
unknownContextRegExp: module.unknownContextRegExp,
|
||||
unknownContextRecursive: module.unknownContextRecursive,
|
||||
unknownContextCritical: module.unknownContextCritical,
|
||||
exprContextRequest: module.exprContextRequest,
|
||||
exprContextRegExp: module.exprContextRegExp,
|
||||
exprContextRecursive: module.exprContextRecursive,
|
||||
exprContextCritical: module.exprContextCritical,
|
||||
wrappedContextRegExp: module.wrappedContextRegExp,
|
||||
wrappedContextRecursive: module.wrappedContextRecursive,
|
||||
wrappedContextCritical: module.wrappedContextCritical,
|
||||
// TODO webpack 6 remove
|
||||
strictExportPresence: module.strictExportPresence,
|
||||
strictThisContextOnImports: module.strictThisContextOnImports,
|
||||
...parserOptions
|
||||
})
|
||||
}),
|
||||
generator: cloneObject(module.generator),
|
||||
defaultRules: optionalNestedArray(module.defaultRules, r => [...r]),
|
||||
rules: nestedArray(module.rules, r => [...r])
|
||||
}))
|
||||
),
|
||||
name: config.name,
|
||||
node: nestedConfig(
|
||||
config.node,
|
||||
node =>
|
||||
node && {
|
||||
...node
|
||||
}
|
||||
),
|
||||
optimization: nestedConfig(config.optimization, optimization => ({
|
||||
...optimization,
|
||||
runtimeChunk: getNormalizedOptimizationRuntimeChunk(
|
||||
optimization.runtimeChunk
|
||||
),
|
||||
splitChunks: nestedConfig(
|
||||
optimization.splitChunks,
|
||||
splitChunks =>
|
||||
splitChunks && {
|
||||
...splitChunks,
|
||||
defaultSizeTypes: splitChunks.defaultSizeTypes
|
||||
? [...splitChunks.defaultSizeTypes]
|
||||
: ["..."],
|
||||
cacheGroups: cloneObject(splitChunks.cacheGroups)
|
||||
}
|
||||
),
|
||||
optimization: nestedConfig(config.optimization, optimization => {
|
||||
return {
|
||||
...optimization,
|
||||
runtimeChunk: getNormalizedOptimizationRuntimeChunk(
|
||||
optimization.runtimeChunk
|
||||
),
|
||||
splitChunks: nestedConfig(
|
||||
optimization.splitChunks,
|
||||
splitChunks =>
|
||||
splitChunks && {
|
||||
...splitChunks,
|
||||
defaultSizeTypes: splitChunks.defaultSizeTypes
|
||||
? [...splitChunks.defaultSizeTypes]
|
||||
: ["..."],
|
||||
cacheGroups: cloneObject(splitChunks.cacheGroups)
|
||||
}
|
||||
),
|
||||
emitOnErrors:
|
||||
optimization.noEmitOnErrors !== undefined
|
||||
? handledDeprecatedNoEmitOnErrors(
|
||||
optimization.noEmitOnErrors,
|
||||
optimization.emitOnErrors
|
||||
)
|
||||
: optimization.emitOnErrors
|
||||
};
|
||||
}),
|
||||
output: nestedConfig(config.output, output => {
|
||||
const { library } = output;
|
||||
const libraryAsName = /** @type {LibraryName} */ (library);
|
||||
const libraryBase =
|
||||
typeof library === "object" &&
|
||||
library &&
|
||||
!Array.isArray(library) &&
|
||||
"type" in library
|
||||
? library
|
||||
: libraryAsName || output.libraryTarget
|
||||
? /** @type {LibraryOptions} */ ({
|
||||
name: libraryAsName
|
||||
})
|
||||
: undefined;
|
||||
/** @type {OutputNormalized} */
|
||||
const result = {
|
||||
assetModuleFilename: output.assetModuleFilename,
|
||||
asyncChunks: output.asyncChunks,
|
||||
charset: output.charset,
|
||||
chunkFilename: output.chunkFilename,
|
||||
chunkFormat: output.chunkFormat,
|
||||
chunkLoading: output.chunkLoading,
|
||||
chunkLoadingGlobal: output.chunkLoadingGlobal,
|
||||
chunkLoadTimeout: output.chunkLoadTimeout,
|
||||
cssFilename: output.cssFilename,
|
||||
cssChunkFilename: output.cssChunkFilename,
|
||||
cssHeadDataCompression: output.cssHeadDataCompression,
|
||||
clean: output.clean,
|
||||
compareBeforeEmit: output.compareBeforeEmit,
|
||||
crossOriginLoading: output.crossOriginLoading,
|
||||
devtoolFallbackModuleFilenameTemplate:
|
||||
output.devtoolFallbackModuleFilenameTemplate,
|
||||
devtoolModuleFilenameTemplate: output.devtoolModuleFilenameTemplate,
|
||||
devtoolNamespace: output.devtoolNamespace,
|
||||
environment: cloneObject(output.environment),
|
||||
enabledChunkLoadingTypes: output.enabledChunkLoadingTypes
|
||||
? [...output.enabledChunkLoadingTypes]
|
||||
: ["..."],
|
||||
enabledLibraryTypes: output.enabledLibraryTypes
|
||||
? [...output.enabledLibraryTypes]
|
||||
: ["..."],
|
||||
enabledWasmLoadingTypes: output.enabledWasmLoadingTypes
|
||||
? [...output.enabledWasmLoadingTypes]
|
||||
: ["..."],
|
||||
filename: output.filename,
|
||||
globalObject: output.globalObject,
|
||||
hashDigest: output.hashDigest,
|
||||
hashDigestLength: output.hashDigestLength,
|
||||
hashFunction: output.hashFunction,
|
||||
hashSalt: output.hashSalt,
|
||||
hotUpdateChunkFilename: output.hotUpdateChunkFilename,
|
||||
hotUpdateGlobal: output.hotUpdateGlobal,
|
||||
hotUpdateMainFilename: output.hotUpdateMainFilename,
|
||||
ignoreBrowserWarnings: output.ignoreBrowserWarnings,
|
||||
iife: output.iife,
|
||||
importFunctionName: output.importFunctionName,
|
||||
importMetaName: output.importMetaName,
|
||||
scriptType: output.scriptType,
|
||||
library: libraryBase && {
|
||||
type:
|
||||
output.libraryTarget !== undefined
|
||||
? output.libraryTarget
|
||||
: libraryBase.type,
|
||||
auxiliaryComment:
|
||||
output.auxiliaryComment !== undefined
|
||||
? output.auxiliaryComment
|
||||
: libraryBase.auxiliaryComment,
|
||||
amdContainer:
|
||||
output.amdContainer !== undefined
|
||||
? output.amdContainer
|
||||
: libraryBase.amdContainer,
|
||||
export:
|
||||
output.libraryExport !== undefined
|
||||
? output.libraryExport
|
||||
: libraryBase.export,
|
||||
name: libraryBase.name,
|
||||
umdNamedDefine:
|
||||
output.umdNamedDefine !== undefined
|
||||
? output.umdNamedDefine
|
||||
: libraryBase.umdNamedDefine
|
||||
},
|
||||
module: output.module,
|
||||
path: output.path,
|
||||
pathinfo: output.pathinfo,
|
||||
publicPath: output.publicPath,
|
||||
sourceMapFilename: output.sourceMapFilename,
|
||||
sourcePrefix: output.sourcePrefix,
|
||||
strictModuleErrorHandling: output.strictModuleErrorHandling,
|
||||
strictModuleExceptionHandling: output.strictModuleExceptionHandling,
|
||||
trustedTypes: optionalNestedConfig(
|
||||
output.trustedTypes,
|
||||
trustedTypes => {
|
||||
if (trustedTypes === true) return {};
|
||||
if (typeof trustedTypes === "string")
|
||||
return { policyName: trustedTypes };
|
||||
return { ...trustedTypes };
|
||||
}
|
||||
),
|
||||
uniqueName: output.uniqueName,
|
||||
wasmLoading: output.wasmLoading,
|
||||
webassemblyModuleFilename: output.webassemblyModuleFilename,
|
||||
workerPublicPath: output.workerPublicPath,
|
||||
workerChunkLoading: output.workerChunkLoading,
|
||||
workerWasmLoading: output.workerWasmLoading
|
||||
};
|
||||
return result;
|
||||
}),
|
||||
parallelism: config.parallelism,
|
||||
performance: optionalNestedConfig(config.performance, performance => {
|
||||
if (performance === false) return false;
|
||||
return {
|
||||
...performance
|
||||
};
|
||||
}),
|
||||
plugins: /** @type {Plugins} */ (nestedArray(config.plugins, p => [...p])),
|
||||
profile: config.profile,
|
||||
recordsInputPath:
|
||||
config.recordsInputPath !== undefined
|
||||
? config.recordsInputPath
|
||||
: config.recordsPath,
|
||||
recordsOutputPath:
|
||||
config.recordsOutputPath !== undefined
|
||||
? config.recordsOutputPath
|
||||
: config.recordsPath,
|
||||
resolve: nestedConfig(config.resolve, resolve => ({
|
||||
...resolve,
|
||||
byDependency: keyedNestedConfig(resolve.byDependency, cloneObject)
|
||||
emitOnErrors:
|
||||
optimization.noEmitOnErrors !== undefined
|
||||
? handledDeprecatedNoEmitOnErrors(
|
||||
optimization.noEmitOnErrors,
|
||||
optimization.emitOnErrors
|
||||
)
|
||||
: optimization.emitOnErrors
|
||||
})),
|
||||
output: nestedConfig(config.output, output => {
|
||||
const { library } = output;
|
||||
const libraryAsName = /** @type {LibraryName} */ (library);
|
||||
const libraryBase =
|
||||
typeof library === "object" &&
|
||||
library &&
|
||||
!Array.isArray(library) &&
|
||||
"type" in library
|
||||
? library
|
||||
: libraryAsName || output.libraryTarget
|
||||
? /** @type {LibraryOptions} */ ({
|
||||
name: libraryAsName
|
||||
})
|
||||
: undefined;
|
||||
/** @type {OutputNormalized} */
|
||||
const result = {
|
||||
assetModuleFilename: output.assetModuleFilename,
|
||||
asyncChunks: output.asyncChunks,
|
||||
charset: output.charset,
|
||||
chunkFilename: output.chunkFilename,
|
||||
chunkFormat: output.chunkFormat,
|
||||
chunkLoading: output.chunkLoading,
|
||||
chunkLoadingGlobal: output.chunkLoadingGlobal,
|
||||
chunkLoadTimeout: output.chunkLoadTimeout,
|
||||
cssFilename: output.cssFilename,
|
||||
cssChunkFilename: output.cssChunkFilename,
|
||||
cssHeadDataCompression: output.cssHeadDataCompression,
|
||||
clean: output.clean,
|
||||
compareBeforeEmit: output.compareBeforeEmit,
|
||||
crossOriginLoading: output.crossOriginLoading,
|
||||
devtoolFallbackModuleFilenameTemplate:
|
||||
output.devtoolFallbackModuleFilenameTemplate,
|
||||
devtoolModuleFilenameTemplate: output.devtoolModuleFilenameTemplate,
|
||||
devtoolNamespace: output.devtoolNamespace,
|
||||
environment: cloneObject(output.environment),
|
||||
enabledChunkLoadingTypes: output.enabledChunkLoadingTypes
|
||||
? [...output.enabledChunkLoadingTypes]
|
||||
: ["..."],
|
||||
enabledLibraryTypes: output.enabledLibraryTypes
|
||||
? [...output.enabledLibraryTypes]
|
||||
: ["..."],
|
||||
enabledWasmLoadingTypes: output.enabledWasmLoadingTypes
|
||||
? [...output.enabledWasmLoadingTypes]
|
||||
: ["..."],
|
||||
filename: output.filename,
|
||||
globalObject: output.globalObject,
|
||||
hashDigest: output.hashDigest,
|
||||
hashDigestLength: output.hashDigestLength,
|
||||
hashFunction: output.hashFunction,
|
||||
hashSalt: output.hashSalt,
|
||||
hotUpdateChunkFilename: output.hotUpdateChunkFilename,
|
||||
hotUpdateGlobal: output.hotUpdateGlobal,
|
||||
hotUpdateMainFilename: output.hotUpdateMainFilename,
|
||||
ignoreBrowserWarnings: output.ignoreBrowserWarnings,
|
||||
iife: output.iife,
|
||||
importFunctionName: output.importFunctionName,
|
||||
importMetaName: output.importMetaName,
|
||||
scriptType: output.scriptType,
|
||||
library: libraryBase && {
|
||||
type:
|
||||
output.libraryTarget !== undefined
|
||||
? output.libraryTarget
|
||||
: libraryBase.type,
|
||||
auxiliaryComment:
|
||||
output.auxiliaryComment !== undefined
|
||||
? output.auxiliaryComment
|
||||
: libraryBase.auxiliaryComment,
|
||||
amdContainer:
|
||||
output.amdContainer !== undefined
|
||||
? output.amdContainer
|
||||
: libraryBase.amdContainer,
|
||||
export:
|
||||
output.libraryExport !== undefined
|
||||
? output.libraryExport
|
||||
: libraryBase.export,
|
||||
name: libraryBase.name,
|
||||
umdNamedDefine:
|
||||
output.umdNamedDefine !== undefined
|
||||
? output.umdNamedDefine
|
||||
: libraryBase.umdNamedDefine
|
||||
},
|
||||
module: output.module,
|
||||
path: output.path,
|
||||
pathinfo: output.pathinfo,
|
||||
publicPath: output.publicPath,
|
||||
sourceMapFilename: output.sourceMapFilename,
|
||||
sourcePrefix: output.sourcePrefix,
|
||||
strictModuleErrorHandling: output.strictModuleErrorHandling,
|
||||
strictModuleExceptionHandling: output.strictModuleExceptionHandling,
|
||||
trustedTypes: optionalNestedConfig(output.trustedTypes, trustedTypes => {
|
||||
if (trustedTypes === true) return {};
|
||||
if (typeof trustedTypes === "string")
|
||||
return { policyName: trustedTypes };
|
||||
return { ...trustedTypes };
|
||||
}),
|
||||
uniqueName: output.uniqueName,
|
||||
wasmLoading: output.wasmLoading,
|
||||
webassemblyModuleFilename: output.webassemblyModuleFilename,
|
||||
workerPublicPath: output.workerPublicPath,
|
||||
workerChunkLoading: output.workerChunkLoading,
|
||||
workerWasmLoading: output.workerWasmLoading
|
||||
};
|
||||
return result;
|
||||
}),
|
||||
parallelism: config.parallelism,
|
||||
performance: optionalNestedConfig(config.performance, performance => {
|
||||
if (performance === false) return false;
|
||||
return {
|
||||
...performance
|
||||
};
|
||||
}),
|
||||
plugins: /** @type {Plugins} */ (nestedArray(config.plugins, p => [...p])),
|
||||
profile: config.profile,
|
||||
recordsInputPath:
|
||||
config.recordsInputPath !== undefined
|
||||
? config.recordsInputPath
|
||||
: config.recordsPath,
|
||||
recordsOutputPath:
|
||||
config.recordsOutputPath !== undefined
|
||||
? config.recordsOutputPath
|
||||
: config.recordsPath,
|
||||
resolve: nestedConfig(config.resolve, resolve => ({
|
||||
...resolve,
|
||||
byDependency: keyedNestedConfig(resolve.byDependency, cloneObject)
|
||||
})),
|
||||
resolveLoader: cloneObject(config.resolveLoader),
|
||||
snapshot: nestedConfig(config.snapshot, snapshot => ({
|
||||
resolveBuildDependencies: optionalNestedConfig(
|
||||
snapshot.resolveBuildDependencies,
|
||||
resolveBuildDependencies => ({
|
||||
timestamp: resolveBuildDependencies.timestamp,
|
||||
hash: resolveBuildDependencies.hash
|
||||
})
|
||||
),
|
||||
buildDependencies: optionalNestedConfig(
|
||||
snapshot.buildDependencies,
|
||||
buildDependencies => ({
|
||||
timestamp: buildDependencies.timestamp,
|
||||
hash: buildDependencies.hash
|
||||
})
|
||||
),
|
||||
resolve: optionalNestedConfig(snapshot.resolve, resolve => ({
|
||||
timestamp: resolve.timestamp,
|
||||
hash: resolve.hash
|
||||
})),
|
||||
resolveLoader: cloneObject(config.resolveLoader),
|
||||
snapshot: nestedConfig(config.snapshot, snapshot => ({
|
||||
resolveBuildDependencies: optionalNestedConfig(
|
||||
snapshot.resolveBuildDependencies,
|
||||
resolveBuildDependencies => ({
|
||||
timestamp: resolveBuildDependencies.timestamp,
|
||||
hash: resolveBuildDependencies.hash
|
||||
})
|
||||
),
|
||||
buildDependencies: optionalNestedConfig(
|
||||
snapshot.buildDependencies,
|
||||
buildDependencies => ({
|
||||
timestamp: buildDependencies.timestamp,
|
||||
hash: buildDependencies.hash
|
||||
})
|
||||
),
|
||||
resolve: optionalNestedConfig(snapshot.resolve, resolve => ({
|
||||
timestamp: resolve.timestamp,
|
||||
hash: resolve.hash
|
||||
})),
|
||||
module: optionalNestedConfig(snapshot.module, module => ({
|
||||
timestamp: module.timestamp,
|
||||
hash: module.hash
|
||||
})),
|
||||
immutablePaths: optionalNestedArray(snapshot.immutablePaths, p => [...p]),
|
||||
managedPaths: optionalNestedArray(snapshot.managedPaths, p => [...p]),
|
||||
unmanagedPaths: optionalNestedArray(snapshot.unmanagedPaths, p => [...p])
|
||||
module: optionalNestedConfig(snapshot.module, module => ({
|
||||
timestamp: module.timestamp,
|
||||
hash: module.hash
|
||||
})),
|
||||
stats: nestedConfig(config.stats, stats => {
|
||||
if (stats === false) {
|
||||
return {
|
||||
preset: "none"
|
||||
};
|
||||
}
|
||||
if (stats === true) {
|
||||
return {
|
||||
preset: "normal"
|
||||
};
|
||||
}
|
||||
if (typeof stats === "string") {
|
||||
return {
|
||||
preset: stats
|
||||
};
|
||||
}
|
||||
immutablePaths: optionalNestedArray(snapshot.immutablePaths, p => [...p]),
|
||||
managedPaths: optionalNestedArray(snapshot.managedPaths, p => [...p]),
|
||||
unmanagedPaths: optionalNestedArray(snapshot.unmanagedPaths, p => [...p])
|
||||
})),
|
||||
stats: nestedConfig(config.stats, stats => {
|
||||
if (stats === false) {
|
||||
return {
|
||||
...stats
|
||||
preset: "none"
|
||||
};
|
||||
}),
|
||||
target: config.target,
|
||||
watch: config.watch,
|
||||
watchOptions: cloneObject(config.watchOptions)
|
||||
};
|
||||
};
|
||||
}
|
||||
if (stats === true) {
|
||||
return {
|
||||
preset: "normal"
|
||||
};
|
||||
}
|
||||
if (typeof stats === "string") {
|
||||
return {
|
||||
preset: stats
|
||||
};
|
||||
}
|
||||
return {
|
||||
...stats
|
||||
};
|
||||
}),
|
||||
target: config.target,
|
||||
watch: config.watch,
|
||||
watchOptions: cloneObject(config.watchOptions)
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {EntryStatic} entry static entry options
|
||||
@@ -543,7 +534,7 @@ const getNormalizedEntryStatic = entry => {
|
||||
* @returns {OptimizationRuntimeChunkNormalized=} normalized runtimeChunk option
|
||||
*/
|
||||
const getNormalizedOptimizationRuntimeChunk = runtimeChunk => {
|
||||
if (runtimeChunk === undefined) return undefined;
|
||||
if (runtimeChunk === undefined) return;
|
||||
if (runtimeChunk === false) return false;
|
||||
if (runtimeChunk === "single") {
|
||||
return {
|
||||
@@ -565,4 +556,4 @@ const getNormalizedOptimizationRuntimeChunk = runtimeChunk => {
|
||||
};
|
||||
};
|
||||
|
||||
exports.getNormalizedWebpackOptions = getNormalizedWebpackOptions;
|
||||
module.exports.getNormalizedWebpackOptions = getNormalizedWebpackOptions;
|
||||
|
||||
94
node_modules/webpack/lib/config/target.js
generated
vendored
94
node_modules/webpack/lib/config/target.js
generated
vendored
@@ -65,8 +65,6 @@ const getDefaultTarget = context => {
|
||||
* @property {boolean | null} asyncFunction async functions and await are available
|
||||
*/
|
||||
|
||||
///** @typedef {PlatformTargetProperties | ApiTargetProperties | EcmaTargetProperties | PlatformTargetProperties & ApiTargetProperties | PlatformTargetProperties & EcmaTargetProperties | ApiTargetProperties & EcmaTargetProperties} TargetProperties */
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @typedef {{ [P in keyof T]?: never }} Never<T>
|
||||
@@ -90,12 +88,11 @@ const versionDependent = (major, minor) => {
|
||||
return () => /** @type {undefined} */ (undefined);
|
||||
}
|
||||
/** @type {number} */
|
||||
const nMajor = +major;
|
||||
const nMajor = Number(major);
|
||||
/** @type {number} */
|
||||
const nMinor = minor ? +minor : 0;
|
||||
return (vMajor, vMinor = 0) => {
|
||||
return nMajor > vMajor || (nMajor === vMajor && nMinor >= vMinor);
|
||||
};
|
||||
const nMinor = minor ? Number(minor) : 0;
|
||||
return (vMajor, vMinor = 0) =>
|
||||
nMajor > vMajor || (nMajor === vMajor && nMinor >= vMinor);
|
||||
};
|
||||
|
||||
/** @type {[string, string, RegExp, (...args: string[]) => Partial<TargetProperties>][]} */
|
||||
@@ -124,47 +121,43 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
||||
"web",
|
||||
"Web browser.",
|
||||
/^web$/,
|
||||
() => {
|
||||
return {
|
||||
web: true,
|
||||
browser: true,
|
||||
webworker: null,
|
||||
node: false,
|
||||
electron: false,
|
||||
nwjs: false,
|
||||
() => ({
|
||||
web: true,
|
||||
browser: true,
|
||||
webworker: null,
|
||||
node: false,
|
||||
electron: false,
|
||||
nwjs: false,
|
||||
|
||||
document: true,
|
||||
importScriptsInWorker: true,
|
||||
fetchWasm: true,
|
||||
nodeBuiltins: false,
|
||||
importScripts: false,
|
||||
require: false,
|
||||
global: false
|
||||
};
|
||||
}
|
||||
document: true,
|
||||
importScriptsInWorker: true,
|
||||
fetchWasm: true,
|
||||
nodeBuiltins: false,
|
||||
importScripts: false,
|
||||
require: false,
|
||||
global: false
|
||||
})
|
||||
],
|
||||
[
|
||||
"webworker",
|
||||
"Web Worker, SharedWorker or Service Worker.",
|
||||
/^webworker$/,
|
||||
() => {
|
||||
return {
|
||||
web: true,
|
||||
browser: true,
|
||||
webworker: true,
|
||||
node: false,
|
||||
electron: false,
|
||||
nwjs: false,
|
||||
() => ({
|
||||
web: true,
|
||||
browser: true,
|
||||
webworker: true,
|
||||
node: false,
|
||||
electron: false,
|
||||
nwjs: false,
|
||||
|
||||
importScripts: true,
|
||||
importScriptsInWorker: true,
|
||||
fetchWasm: true,
|
||||
nodeBuiltins: false,
|
||||
require: false,
|
||||
document: false,
|
||||
global: false
|
||||
};
|
||||
}
|
||||
importScripts: true,
|
||||
importScriptsInWorker: true,
|
||||
fetchWasm: true,
|
||||
nodeBuiltins: false,
|
||||
require: false,
|
||||
document: false,
|
||||
global: false
|
||||
})
|
||||
],
|
||||
[
|
||||
"[async-]node[X[.Y]]",
|
||||
@@ -184,7 +177,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
||||
require: !asyncFlag,
|
||||
nodeBuiltins: true,
|
||||
// v16.0.0, v14.18.0
|
||||
nodePrefixForCoreModules: +major < 15 ? v(14, 18) : v(16),
|
||||
nodePrefixForCoreModules: Number(major) < 15 ? v(14, 18) : v(16),
|
||||
global: true,
|
||||
document: false,
|
||||
fetchWasm: false,
|
||||
@@ -295,7 +288,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
||||
"EcmaScript in this version. Examples: es2020, es5.",
|
||||
/^es(\d+)$/,
|
||||
version => {
|
||||
let v = +version;
|
||||
let v = Number(version);
|
||||
if (v < 1000) v = v + 2009;
|
||||
return {
|
||||
const: v >= 2015,
|
||||
@@ -366,7 +359,7 @@ const mergeTargetProperties = targetProperties => {
|
||||
}
|
||||
if (hasTrue || hasFalse)
|
||||
/** @type {TargetProperties} */
|
||||
(result)[key] = hasFalse && hasTrue ? null : hasTrue ? true : false;
|
||||
(result)[key] = hasFalse && hasTrue ? null : Boolean(hasTrue);
|
||||
}
|
||||
return /** @type {TargetProperties} */ (result);
|
||||
};
|
||||
@@ -376,12 +369,9 @@ const mergeTargetProperties = targetProperties => {
|
||||
* @param {string} context the context directory
|
||||
* @returns {TargetProperties} target properties
|
||||
*/
|
||||
const getTargetsProperties = (targets, context) => {
|
||||
return mergeTargetProperties(
|
||||
targets.map(t => getTargetProperties(t, context))
|
||||
);
|
||||
};
|
||||
const getTargetsProperties = (targets, context) =>
|
||||
mergeTargetProperties(targets.map(t => getTargetProperties(t, context)));
|
||||
|
||||
exports.getDefaultTarget = getDefaultTarget;
|
||||
exports.getTargetProperties = getTargetProperties;
|
||||
exports.getTargetsProperties = getTargetsProperties;
|
||||
module.exports.getDefaultTarget = getDefaultTarget;
|
||||
module.exports.getTargetProperties = getTargetProperties;
|
||||
module.exports.getTargetsProperties = getTargetsProperties;
|
||||
|
||||
Reference in New Issue
Block a user