mirror of https://github.com/alibaba/ice.git
feat: rax-compat 0.3.0
This commit is contained in:
parent
d48b8eed49
commit
4d72b003b0
|
@ -71,7 +71,8 @@
|
|||
"packageManager": "pnpm@8.9.2",
|
||||
"pnpm": {
|
||||
"patchedDependencies": {
|
||||
"unplugin@1.5.1": "patches/unplugin@1.5.1.patch"
|
||||
"unplugin@1.5.1": "patches/unplugin@1.5.1.patch",
|
||||
"@rspack/core@0.4.3": "patches/@rspack__core@0.4.3.patch"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,669 +0,0 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getRawChunkLoading = exports.getRawEntryRuntime = exports.toRawSplitChunksOptions = exports.getRawLibrary = exports.getRawOptions = void 0;
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const Stats_1 = require("../Stats");
|
||||
const util_1 = require("../util");
|
||||
const identifier_1 = require("../util/identifier");
|
||||
const adapterRuleUse_1 = require("./adapterRuleUse");
|
||||
const Module_1 = require("../Module");
|
||||
const getRawOptions = (options, compiler, processResource) => {
|
||||
var _a, _b;
|
||||
(0, assert_1.default)(!(0, util_1.isNil)(options.context) && !(0, util_1.isNil)(options.devtool) && !(0, util_1.isNil)(options.cache), "context, devtool, cache should not be nil after defaults");
|
||||
const devtool = options.devtool === false ? "" : options.devtool;
|
||||
const mode = options.mode;
|
||||
const experiments = getRawExperiments(options.experiments);
|
||||
return {
|
||||
// CUSTOM: add options of features.
|
||||
features: options.features,
|
||||
mode,
|
||||
target: getRawTarget(options.target),
|
||||
context: options.context,
|
||||
output: getRawOutput(options.output),
|
||||
resolve: getRawResolve(options.resolve),
|
||||
resolveLoader: getRawResolve(options.resolveLoader),
|
||||
module: getRawModule(options.module, {
|
||||
compiler,
|
||||
devtool,
|
||||
mode,
|
||||
context: options.context,
|
||||
experiments
|
||||
}),
|
||||
devtool,
|
||||
optimization: getRawOptimization(options.optimization),
|
||||
stats: getRawStats(options.stats),
|
||||
devServer: {
|
||||
hot: (_b = (_a = options.devServer) === null || _a === void 0 ? void 0 : _a.hot) !== null && _b !== void 0 ? _b : false
|
||||
},
|
||||
snapshot: getRawSnapshotOptions(options.snapshot),
|
||||
cache: {
|
||||
type: options.cache ? "memory" : "disable",
|
||||
// TODO: implement below cache options
|
||||
maxGenerations: 0,
|
||||
maxAge: 0,
|
||||
profile: false,
|
||||
buildDependencies: [],
|
||||
cacheDirectory: "",
|
||||
cacheLocation: "",
|
||||
name: "",
|
||||
version: ""
|
||||
},
|
||||
experiments,
|
||||
node: getRawNode(options.node),
|
||||
profile: options.profile,
|
||||
// TODO: remove this
|
||||
builtins: options.builtins
|
||||
};
|
||||
};
|
||||
exports.getRawOptions = getRawOptions;
|
||||
function getRawTarget(target) {
|
||||
if (!target) {
|
||||
return [];
|
||||
}
|
||||
if (typeof target === "string") {
|
||||
return [target];
|
||||
}
|
||||
return target;
|
||||
}
|
||||
function getRawAlias(alias = {}) {
|
||||
const entires = Object.entries(alias).map(([key, value]) => {
|
||||
if (Array.isArray(value)) {
|
||||
return [key, value];
|
||||
}
|
||||
else {
|
||||
return [key, [value]];
|
||||
}
|
||||
});
|
||||
return Object.fromEntries(entires);
|
||||
}
|
||||
function getRawResolveByDependency(byDependency) {
|
||||
if (byDependency === undefined)
|
||||
return byDependency;
|
||||
return Object.fromEntries(Object.entries(byDependency).map(([k, v]) => [k, getRawResolve(v)]));
|
||||
}
|
||||
function getRawResolve(resolve) {
|
||||
var _a, _b, _c;
|
||||
let references = (_a = resolve.tsConfig) === null || _a === void 0 ? void 0 : _a.references;
|
||||
let tsconfigConfigFile = (_b = resolve.tsConfigPath) !== null && _b !== void 0 ? _b : (_c = resolve.tsConfig) === null || _c === void 0 ? void 0 : _c.configFile;
|
||||
return {
|
||||
...resolve,
|
||||
alias: getRawAlias(resolve.alias),
|
||||
fallback: getRawAlias(resolve.fallback),
|
||||
extensionAlias: getRawAlias(resolve.extensionAlias),
|
||||
tsconfig: tsconfigConfigFile
|
||||
? {
|
||||
configFile: tsconfigConfigFile,
|
||||
referencesType: references == "auto" ? "auto" : references ? "manual" : "disabled",
|
||||
references: references == "auto" ? undefined : references
|
||||
}
|
||||
: undefined,
|
||||
byDependency: getRawResolveByDependency(resolve.byDependency)
|
||||
};
|
||||
}
|
||||
function getRawCrossOriginLoading(crossOriginLoading) {
|
||||
if (typeof crossOriginLoading === "boolean") {
|
||||
return { type: "bool", boolPayload: crossOriginLoading };
|
||||
}
|
||||
return { type: "string", stringPayload: crossOriginLoading };
|
||||
}
|
||||
function getRawOutput(output) {
|
||||
const chunkLoading = output.chunkLoading;
|
||||
const wasmLoading = output.wasmLoading;
|
||||
const workerChunkLoading = output.workerChunkLoading;
|
||||
const workerWasmLoading = output.workerWasmLoading;
|
||||
return {
|
||||
path: output.path,
|
||||
publicPath: output.publicPath,
|
||||
clean: output.clean,
|
||||
assetModuleFilename: output.assetModuleFilename,
|
||||
filename: output.filename,
|
||||
chunkFilename: output.chunkFilename,
|
||||
chunkLoading: getRawChunkLoading(chunkLoading),
|
||||
crossOriginLoading: getRawCrossOriginLoading(output.crossOriginLoading),
|
||||
cssFilename: output.cssFilename,
|
||||
cssChunkFilename: output.cssChunkFilename,
|
||||
hotUpdateChunkFilename: output.hotUpdateChunkFilename,
|
||||
hotUpdateMainFilename: output.hotUpdateMainFilename,
|
||||
hotUpdateGlobal: output.hotUpdateGlobal,
|
||||
uniqueName: output.uniqueName,
|
||||
chunkLoadingGlobal: output.chunkLoadingGlobal,
|
||||
enabledLibraryTypes: output.enabledLibraryTypes,
|
||||
library: output.library && getRawLibrary(output.library),
|
||||
strictModuleErrorHandling: output.strictModuleErrorHandling,
|
||||
globalObject: output.globalObject,
|
||||
importFunctionName: output.importFunctionName,
|
||||
iife: output.iife,
|
||||
module: output.module,
|
||||
wasmLoading: wasmLoading === false ? "false" : wasmLoading,
|
||||
enabledWasmLoadingTypes: output.enabledWasmLoadingTypes,
|
||||
enabledChunkLoadingTypes: output.enabledChunkLoadingTypes,
|
||||
webassemblyModuleFilename: output.webassemblyModuleFilename,
|
||||
trustedTypes: output.trustedTypes,
|
||||
sourceMapFilename: output.sourceMapFilename,
|
||||
hashFunction: output.hashFunction,
|
||||
hashDigest: output.hashDigest,
|
||||
hashDigestLength: output.hashDigestLength,
|
||||
hashSalt: output.hashSalt,
|
||||
asyncChunks: output.asyncChunks,
|
||||
workerChunkLoading: workerChunkLoading === false ? "false" : workerChunkLoading,
|
||||
workerWasmLoading: workerWasmLoading === false ? "false" : workerWasmLoading,
|
||||
workerPublicPath: output.workerPublicPath,
|
||||
scriptType: output.scriptType === false ? "false" : output.scriptType
|
||||
};
|
||||
}
|
||||
function getRawLibrary(library) {
|
||||
const { type, name, export: libraryExport, umdNamedDefine, auxiliaryComment, amdContainer } = library;
|
||||
return {
|
||||
amdContainer,
|
||||
auxiliaryComment: typeof auxiliaryComment === "string"
|
||||
? {
|
||||
commonjs: auxiliaryComment,
|
||||
commonjs2: auxiliaryComment,
|
||||
amd: auxiliaryComment,
|
||||
root: auxiliaryComment
|
||||
}
|
||||
: auxiliaryComment,
|
||||
libraryType: type,
|
||||
name: (0, util_1.isNil)(name) ? name : getRawLibraryName(name),
|
||||
export: Array.isArray(libraryExport) || libraryExport == null
|
||||
? libraryExport
|
||||
: [libraryExport],
|
||||
umdNamedDefine
|
||||
};
|
||||
}
|
||||
exports.getRawLibrary = getRawLibrary;
|
||||
function getRawLibraryName(name) {
|
||||
if (typeof name === "string") {
|
||||
return {
|
||||
type: "string",
|
||||
stringPayload: name
|
||||
};
|
||||
}
|
||||
if (Array.isArray(name)) {
|
||||
return {
|
||||
type: "array",
|
||||
arrayPayload: name
|
||||
};
|
||||
}
|
||||
if (typeof name === "object" && !Array.isArray(name)) {
|
||||
return {
|
||||
type: "umdObject",
|
||||
umdObjectPayload: {
|
||||
commonjs: name.commonjs,
|
||||
root: Array.isArray(name.root) || (0, util_1.isNil)(name.root)
|
||||
? name.root
|
||||
: [name.root],
|
||||
amd: name.amd
|
||||
}
|
||||
};
|
||||
}
|
||||
throw new Error("unreachable");
|
||||
}
|
||||
function getRawModule(module, options) {
|
||||
(0, assert_1.default)(!(0, util_1.isNil)(module.defaultRules), "module.defaultRules should not be nil after defaults");
|
||||
// "..." in defaultRules will be flatten in `applyModuleDefaults`, and "..." in rules is empty, so it's safe to use `as RuleSetRule[]` at here
|
||||
const ruleSet = [
|
||||
{ rules: module.defaultRules },
|
||||
{ rules: module.rules }
|
||||
];
|
||||
const rules = ruleSet.map((rule, index) => getRawModuleRule(rule, `ruleSet[${index}]`, options));
|
||||
return {
|
||||
rules,
|
||||
parser: getRawParserOptionsByModuleType(module.parser),
|
||||
generator: getRawGeneratorOptionsByModuleType(module.generator)
|
||||
};
|
||||
}
|
||||
function tryMatch(payload, condition) {
|
||||
if (typeof condition === "string") {
|
||||
return payload.startsWith(condition);
|
||||
}
|
||||
if (condition instanceof RegExp) {
|
||||
return condition.test(payload);
|
||||
}
|
||||
if (typeof condition === "function") {
|
||||
return condition(payload);
|
||||
}
|
||||
if (Array.isArray(condition)) {
|
||||
return condition.some(c => tryMatch(payload, c));
|
||||
}
|
||||
if (condition && typeof condition === "object") {
|
||||
if (condition.and) {
|
||||
return condition.and.every(c => tryMatch(payload, c));
|
||||
}
|
||||
if (condition.or) {
|
||||
return condition.or.some(c => tryMatch(payload, c));
|
||||
}
|
||||
if (condition.not) {
|
||||
return condition.not.every(c => !tryMatch(payload, c));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const deprecatedRuleType = (type) => {
|
||||
type !== null && type !== void 0 ? type : (type = "javascript/auto");
|
||||
if (/ts|typescript|tsx|typescriptx|jsx|javascriptx/.test(type)) {
|
||||
(0, util_1.deprecatedWarn)(`'Rule.type: ${type}' has been deprecated, please migrate to builtin:swc-loader with type 'javascript/auto'`);
|
||||
}
|
||||
};
|
||||
const getRawModuleRule = (rule, path, options) => {
|
||||
var _a, _b, _c;
|
||||
// Rule.loader is a shortcut to Rule.use: [ { loader } ].
|
||||
// See: https://webpack.js.org/configuration/module/#ruleloader
|
||||
if (rule.loader) {
|
||||
rule.use = [
|
||||
{
|
||||
loader: rule.loader,
|
||||
options: rule.options
|
||||
}
|
||||
];
|
||||
}
|
||||
let funcUse;
|
||||
if (typeof rule.use === "function") {
|
||||
funcUse = (rawContext) => {
|
||||
const context = {
|
||||
...rawContext,
|
||||
compiler: options.compiler
|
||||
};
|
||||
const uses = rule.use(context);
|
||||
return (0, adapterRuleUse_1.createRawModuleRuleUses)(uses !== null && uses !== void 0 ? uses : [], `${path}.use`, options);
|
||||
};
|
||||
}
|
||||
let rawModuleRule = {
|
||||
test: rule.test ? getRawRuleSetCondition(rule.test) : undefined,
|
||||
include: rule.include ? getRawRuleSetCondition(rule.include) : undefined,
|
||||
exclude: rule.exclude ? getRawRuleSetCondition(rule.exclude) : undefined,
|
||||
issuer: rule.issuer ? getRawRuleSetCondition(rule.issuer) : undefined,
|
||||
dependency: rule.dependency
|
||||
? getRawRuleSetCondition(rule.dependency)
|
||||
: undefined,
|
||||
descriptionData: rule.descriptionData
|
||||
? Object.fromEntries(Object.entries(rule.descriptionData).map(([k, v]) => [
|
||||
k,
|
||||
getRawRuleSetCondition(v)
|
||||
]))
|
||||
: undefined,
|
||||
resource: rule.resource ? getRawRuleSetCondition(rule.resource) : undefined,
|
||||
resourceQuery: rule.resourceQuery
|
||||
? getRawRuleSetCondition(rule.resourceQuery)
|
||||
: undefined,
|
||||
resourceFragment: rule.resourceFragment
|
||||
? getRawRuleSetCondition(rule.resourceFragment)
|
||||
: undefined,
|
||||
scheme: rule.scheme ? getRawRuleSetCondition(rule.scheme) : undefined,
|
||||
mimetype: rule.mimetype ? getRawRuleSetCondition(rule.mimetype) : undefined,
|
||||
sideEffects: rule.sideEffects,
|
||||
use: typeof rule.use === "function"
|
||||
? { type: "function", funcUse }
|
||||
: {
|
||||
type: "array",
|
||||
arrayUse: (0, adapterRuleUse_1.createRawModuleRuleUses)((_a = rule.use) !== null && _a !== void 0 ? _a : [], `${path}.use`, options)
|
||||
},
|
||||
type: rule.type,
|
||||
parser: rule.parser
|
||||
? getRawParserOptions(rule.parser, (_b = rule.type) !== null && _b !== void 0 ? _b : "javascript/auto")
|
||||
: undefined,
|
||||
generator: rule.generator
|
||||
? getRawGeneratorOptions(rule.generator, (_c = rule.type) !== null && _c !== void 0 ? _c : "javascript/auto")
|
||||
: undefined,
|
||||
resolve: rule.resolve ? getRawResolve(rule.resolve) : undefined,
|
||||
oneOf: rule.oneOf
|
||||
? rule.oneOf.map((rule, index) => getRawModuleRule(rule, `${path}.oneOf[${index}]`, options))
|
||||
: undefined,
|
||||
rules: rule.rules
|
||||
? rule.rules.map((rule, index) => getRawModuleRule(rule, `${path}.rules[${index}]`, options))
|
||||
: undefined,
|
||||
enforce: rule.enforce
|
||||
};
|
||||
// Function calls may contain side-effects when interoperating with single-threaded environment.
|
||||
// In order to mitigate the issue, Rspack tries to merge these calls together.
|
||||
// See: https://github.com/web-infra-dev/rspack/issues/4003#issuecomment-1689662380
|
||||
if (typeof rule.test === "function" ||
|
||||
typeof rule.resource === "function" ||
|
||||
typeof rule.resourceQuery === "function" ||
|
||||
typeof rule.resourceFragment === "function") {
|
||||
delete rawModuleRule.test;
|
||||
delete rawModuleRule.resource;
|
||||
delete rawModuleRule.resourceQuery;
|
||||
delete rawModuleRule.resourceFragment;
|
||||
rawModuleRule.rspackResource = getRawRuleSetCondition(function (resourceQueryFragment) {
|
||||
const { path, query, fragment } = (0, identifier_1.parseResource)(resourceQueryFragment);
|
||||
if (rule.test && !tryMatch(path, rule.test)) {
|
||||
return false;
|
||||
}
|
||||
else if (rule.resource && !tryMatch(path, rule.resource)) {
|
||||
return false;
|
||||
}
|
||||
if (rule.resourceQuery && !tryMatch(query, rule.resourceQuery)) {
|
||||
return false;
|
||||
}
|
||||
if (rule.resourceFragment && !tryMatch(fragment, rule.resourceFragment)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
if (options.experiments.rspackFuture.disableTransformByDefault) {
|
||||
deprecatedRuleType(rule.type);
|
||||
}
|
||||
return rawModuleRule;
|
||||
};
|
||||
function getRawRuleSetCondition(condition) {
|
||||
if (typeof condition === "string") {
|
||||
return {
|
||||
type: "string",
|
||||
stringMatcher: condition
|
||||
};
|
||||
}
|
||||
if (condition instanceof RegExp) {
|
||||
return {
|
||||
type: "regexp",
|
||||
regexpMatcher: {
|
||||
source: condition.source,
|
||||
flags: condition.flags
|
||||
}
|
||||
};
|
||||
}
|
||||
if (typeof condition === "function") {
|
||||
return {
|
||||
type: "function",
|
||||
funcMatcher: condition
|
||||
};
|
||||
}
|
||||
if (Array.isArray(condition)) {
|
||||
return {
|
||||
type: "array",
|
||||
arrayMatcher: condition.map(i => getRawRuleSetCondition(i))
|
||||
};
|
||||
}
|
||||
if (typeof condition === "object" && condition !== null) {
|
||||
return {
|
||||
type: "logical",
|
||||
logicalMatcher: [getRawRuleSetLogicalConditions(condition)]
|
||||
};
|
||||
}
|
||||
throw new Error("unreachable: condition should be one of string, RegExp, Array, Object");
|
||||
}
|
||||
function getRawRuleSetLogicalConditions(logical) {
|
||||
return {
|
||||
and: logical.and
|
||||
? logical.and.map(i => getRawRuleSetCondition(i))
|
||||
: undefined,
|
||||
or: logical.or ? logical.or.map(i => getRawRuleSetCondition(i)) : undefined,
|
||||
not: logical.not ? getRawRuleSetCondition(logical.not) : undefined
|
||||
};
|
||||
}
|
||||
function getRawParserOptionsByModuleType(parser) {
|
||||
return Object.fromEntries(Object.entries(parser).map(([k, v]) => [k, getRawParserOptions(v, k)]));
|
||||
}
|
||||
function getRawGeneratorOptionsByModuleType(parser) {
|
||||
return Object.fromEntries(Object.entries(parser).map(([k, v]) => [k, getRawGeneratorOptions(v, k)]));
|
||||
}
|
||||
function getRawParserOptions(parser, type) {
|
||||
if (type === "asset") {
|
||||
return {
|
||||
type: "asset",
|
||||
asset: getRawAssetParserOptions(parser)
|
||||
};
|
||||
}
|
||||
else if (type === "javascript") {
|
||||
return {
|
||||
type: "javascript",
|
||||
javascript: getRawJavascriptParserOptions(parser)
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: "unknown"
|
||||
};
|
||||
}
|
||||
function getRawJavascriptParserOptions(parser) {
|
||||
var _a;
|
||||
return {
|
||||
dynamicImportMode: (_a = parser.dynamicImportMode) !== null && _a !== void 0 ? _a : "lazy"
|
||||
};
|
||||
}
|
||||
function getRawAssetParserOptions(parser) {
|
||||
return {
|
||||
dataUrlCondition: parser.dataUrlCondition
|
||||
? getRawAssetParserDataUrl(parser.dataUrlCondition)
|
||||
: undefined
|
||||
};
|
||||
}
|
||||
function getRawAssetParserDataUrl(dataUrlCondition) {
|
||||
if (typeof dataUrlCondition === "object" && dataUrlCondition !== null) {
|
||||
return {
|
||||
type: "options",
|
||||
options: {
|
||||
maxSize: dataUrlCondition.maxSize
|
||||
}
|
||||
};
|
||||
}
|
||||
throw new Error(`unreachable: AssetParserDataUrl type should be one of "options", but got ${dataUrlCondition}`);
|
||||
}
|
||||
function getRawGeneratorOptions(generator, type) {
|
||||
if (type === "asset") {
|
||||
return {
|
||||
type: "asset",
|
||||
asset: generator ? getRawAssetGeneratorOptions(generator) : undefined
|
||||
};
|
||||
}
|
||||
if (type === "asset/inline") {
|
||||
return {
|
||||
type: "asset/inline",
|
||||
assetInline: generator
|
||||
? getRawAssetInlineGeneratorOptions(generator)
|
||||
: undefined
|
||||
};
|
||||
}
|
||||
if (type === "asset/resource") {
|
||||
return {
|
||||
type: "asset/resource",
|
||||
assetResource: generator
|
||||
? getRawAssetResourceGeneratorOptions(generator)
|
||||
: undefined
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: "unknown"
|
||||
};
|
||||
}
|
||||
function getRawAssetGeneratorOptions(options) {
|
||||
return {
|
||||
...getRawAssetInlineGeneratorOptions(options),
|
||||
...getRawAssetResourceGeneratorOptions(options)
|
||||
};
|
||||
}
|
||||
function getRawAssetInlineGeneratorOptions(options) {
|
||||
return {
|
||||
dataUrl: options.dataUrl
|
||||
? getRawAssetGeneratorDaraUrl(options.dataUrl)
|
||||
: undefined
|
||||
};
|
||||
}
|
||||
function getRawAssetResourceGeneratorOptions(options) {
|
||||
return {
|
||||
filename: options.filename,
|
||||
publicPath: options.publicPath
|
||||
};
|
||||
}
|
||||
function getRawAssetGeneratorDaraUrl(dataUrl) {
|
||||
if (typeof dataUrl === "object" && dataUrl !== null) {
|
||||
return {
|
||||
type: "options",
|
||||
options: {
|
||||
encoding: dataUrl.encoding === false ? "false" : dataUrl.encoding,
|
||||
mimetype: dataUrl.mimetype
|
||||
}
|
||||
};
|
||||
}
|
||||
throw new Error(`unreachable: AssetGeneratorDataUrl type should be one of "options", but got ${dataUrl}`);
|
||||
}
|
||||
function getRawOptimization(optimization) {
|
||||
(0, assert_1.default)(!(0, util_1.isNil)(optimization.moduleIds) &&
|
||||
!(0, util_1.isNil)(optimization.chunkIds) &&
|
||||
!(0, util_1.isNil)(optimization.removeAvailableModules) &&
|
||||
!(0, util_1.isNil)(optimization.removeEmptyChunks) &&
|
||||
!(0, util_1.isNil)(optimization.sideEffects) &&
|
||||
!(0, util_1.isNil)(optimization.realContentHash) &&
|
||||
!(0, util_1.isNil)(optimization.providedExports) &&
|
||||
!(0, util_1.isNil)(optimization.usedExports) &&
|
||||
!(0, util_1.isNil)(optimization.innerGraph), "optimization.moduleIds, optimization.removeAvailableModules, optimization.removeEmptyChunks, optimization.sideEffects, optimization.realContentHash, optimization.providedExports, optimization.usedExports, optimization.innerGraph should not be nil after defaults");
|
||||
return {
|
||||
chunkIds: optimization.chunkIds,
|
||||
splitChunks: toRawSplitChunksOptions(optimization.splitChunks),
|
||||
moduleIds: optimization.moduleIds,
|
||||
removeAvailableModules: optimization.removeAvailableModules,
|
||||
removeEmptyChunks: optimization.removeEmptyChunks,
|
||||
sideEffects: String(optimization.sideEffects),
|
||||
realContentHash: optimization.realContentHash,
|
||||
usedExports: String(optimization.usedExports),
|
||||
providedExports: optimization.providedExports,
|
||||
innerGraph: optimization.innerGraph,
|
||||
mangleExports: String(optimization.mangleExports)
|
||||
};
|
||||
}
|
||||
function toRawSplitChunksOptions(sc) {
|
||||
if (!sc) {
|
||||
return;
|
||||
}
|
||||
function getName(name) {
|
||||
if (typeof name === "function") {
|
||||
return (ctx) => {
|
||||
if (typeof ctx.module === "undefined") {
|
||||
return name(undefined);
|
||||
}
|
||||
else {
|
||||
return name(Module_1.Module.__from_binding(ctx.module));
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
function getTest(test) {
|
||||
if (typeof test === "function") {
|
||||
return (ctx) => {
|
||||
if (typeof ctx.module === "undefined") {
|
||||
return test(undefined);
|
||||
}
|
||||
else {
|
||||
return test(Module_1.Module.__from_binding(ctx.module));
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
return test;
|
||||
}
|
||||
}
|
||||
const { name, cacheGroups = {}, ...passThrough } = sc;
|
||||
return {
|
||||
name: getName(name),
|
||||
cacheGroups: Object.entries(cacheGroups)
|
||||
.filter(([_key, group]) => group !== false)
|
||||
.map(([key, group]) => {
|
||||
group = group;
|
||||
const { test, name, ...passThrough } = group;
|
||||
const rawGroup = {
|
||||
key,
|
||||
test: getTest(test),
|
||||
name: getName(name),
|
||||
...passThrough
|
||||
};
|
||||
return rawGroup;
|
||||
}),
|
||||
...passThrough
|
||||
};
|
||||
}
|
||||
exports.toRawSplitChunksOptions = toRawSplitChunksOptions;
|
||||
function getRawSnapshotOptions(snapshot) {
|
||||
const { resolve, module } = snapshot;
|
||||
(0, assert_1.default)(!(0, util_1.isNil)(resolve) && !(0, util_1.isNil)(module));
|
||||
const { timestamp: resolveTimestamp, hash: resolveHash } = resolve;
|
||||
const { timestamp: moduleTimestamp, hash: moduleHash } = module;
|
||||
(0, assert_1.default)(!(0, util_1.isNil)(resolveTimestamp) &&
|
||||
!(0, util_1.isNil)(resolveHash) &&
|
||||
!(0, util_1.isNil)(moduleTimestamp) &&
|
||||
!(0, util_1.isNil)(moduleHash));
|
||||
return {
|
||||
resolve: {
|
||||
timestamp: resolveTimestamp,
|
||||
hash: resolveHash
|
||||
},
|
||||
module: {
|
||||
timestamp: moduleTimestamp,
|
||||
hash: moduleHash
|
||||
}
|
||||
};
|
||||
}
|
||||
function getRawExperiments(experiments) {
|
||||
const { lazyCompilation, incrementalRebuild, asyncWebAssembly, newSplitChunks, topLevelAwait, css, rspackFuture } = experiments;
|
||||
(0, assert_1.default)(!(0, util_1.isNil)(lazyCompilation) &&
|
||||
!(0, util_1.isNil)(incrementalRebuild) &&
|
||||
!(0, util_1.isNil)(asyncWebAssembly) &&
|
||||
!(0, util_1.isNil)(newSplitChunks) &&
|
||||
!(0, util_1.isNil)(topLevelAwait) &&
|
||||
!(0, util_1.isNil)(css) &&
|
||||
!(0, util_1.isNil)(rspackFuture));
|
||||
return {
|
||||
lazyCompilation,
|
||||
incrementalRebuild: getRawIncrementalRebuild(incrementalRebuild),
|
||||
asyncWebAssembly,
|
||||
newSplitChunks,
|
||||
topLevelAwait,
|
||||
css,
|
||||
rspackFuture: getRawRspackFutureOptions(rspackFuture)
|
||||
};
|
||||
}
|
||||
function getRawRspackFutureOptions(future) {
|
||||
(0, assert_1.default)(!(0, util_1.isNil)(future.newResolver));
|
||||
(0, assert_1.default)(!(0, util_1.isNil)(future.newTreeshaking));
|
||||
(0, assert_1.default)(!(0, util_1.isNil)(future.disableTransformByDefault));
|
||||
return {
|
||||
newResolver: future.newResolver,
|
||||
newTreeshaking: future.newTreeshaking,
|
||||
disableTransformByDefault: future.disableTransformByDefault
|
||||
};
|
||||
}
|
||||
function getRawIncrementalRebuild(inc) {
|
||||
if (inc === false) {
|
||||
return {
|
||||
make: false,
|
||||
emitAsset: false
|
||||
};
|
||||
}
|
||||
const { make, emitAsset } = inc;
|
||||
(0, assert_1.default)(!(0, util_1.isNil)(make) && !(0, util_1.isNil)(emitAsset));
|
||||
return {
|
||||
make,
|
||||
emitAsset
|
||||
};
|
||||
}
|
||||
function getRawNode(node) {
|
||||
if (node === false) {
|
||||
return undefined;
|
||||
}
|
||||
(0, assert_1.default)(!(0, util_1.isNil)(node.__dirname) && !(0, util_1.isNil)(node.global) && !(0, util_1.isNil)(node.__filename));
|
||||
return {
|
||||
dirname: String(node.__dirname),
|
||||
filename: String(node.__filename),
|
||||
global: String(node.global)
|
||||
};
|
||||
}
|
||||
function getRawStats(stats) {
|
||||
var _a;
|
||||
const statsOptions = (0, Stats_1.normalizeStatsPreset)(stats);
|
||||
return {
|
||||
colors: (_a = statsOptions.colors) !== null && _a !== void 0 ? _a : false
|
||||
};
|
||||
}
|
||||
function getRawEntryRuntime(runtime) {
|
||||
return runtime === false ? undefined : runtime;
|
||||
}
|
||||
exports.getRawEntryRuntime = getRawEntryRuntime;
|
||||
function getRawChunkLoading(chunkLoading) {
|
||||
return chunkLoading === false ? "false" : chunkLoading;
|
||||
}
|
||||
exports.getRawChunkLoading = getRawChunkLoading;
|
|
@ -1,763 +0,0 @@
|
|||
"use strict";
|
||||
/**
|
||||
* The following code is modified based on
|
||||
* https://github.com/webpack/webpack/blob/4b4ca3b/lib/config/defaults.js
|
||||
*
|
||||
* MIT Licensed
|
||||
* Author Tobias Koppers @sokra
|
||||
* Copyright (c) JS Foundation and other contributors
|
||||
* https://github.com/webpack/webpack/blob/main/LICENSE
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.applyRspackOptionsBaseDefaults = exports.applyRspackOptionsDefaults = void 0;
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const util_1 = require("../util");
|
||||
const cleverMerge_1 = require("../util/cleverMerge");
|
||||
const target_1 = require("./target");
|
||||
const Template_1 = __importDefault(require("../Template"));
|
||||
const assertNotNil_1 = require("../util/assertNotNil");
|
||||
const ModuleTypeConstants_1 = require("../ModuleTypeConstants");
|
||||
const applyRspackOptionsDefaults = (options) => {
|
||||
var _a;
|
||||
F(options, "context", () => process.cwd());
|
||||
F(options, "target", () => {
|
||||
return (0, target_1.getDefaultTarget)(options.context);
|
||||
});
|
||||
const { mode, target } = options;
|
||||
(0, assert_1.default)(!(0, util_1.isNil)(target));
|
||||
let targetProperties = target === false
|
||||
? false
|
||||
: typeof target === "string"
|
||||
? (0, target_1.getTargetProperties)(target, options.context)
|
||||
: (0, target_1.getTargetsProperties)(target, options.context);
|
||||
const development = mode === "development";
|
||||
const production = mode === "production" || !mode;
|
||||
if (typeof options.entry !== "function") {
|
||||
for (const key of Object.keys(options.entry)) {
|
||||
F(options.entry[key], "import", () => ["./src"]);
|
||||
}
|
||||
}
|
||||
F(options, "devtool", () => false);
|
||||
D(options, "watch", false);
|
||||
D(options, "profile", false);
|
||||
const futureDefaults = (_a = options.experiments.futureDefaults) !== null && _a !== void 0 ? _a : false;
|
||||
F(options, "cache", () => development);
|
||||
applyExperimentsDefaults(options.experiments, {
|
||||
cache: options.cache
|
||||
});
|
||||
// CUSTOM: add default rules for features options.
|
||||
if (options.features) {
|
||||
applyFeaturesDefaults(options.features);
|
||||
} else {
|
||||
D(options, 'features', {});
|
||||
}
|
||||
applySnapshotDefaults(options.snapshot, { production });
|
||||
applyModuleDefaults(options.module, {
|
||||
// syncWebAssembly: options.experiments.syncWebAssembly,
|
||||
asyncWebAssembly: options.experiments.asyncWebAssembly,
|
||||
disableTransformByDefault: options.experiments.rspackFuture.disableTransformByDefault,
|
||||
css: options.experiments.css
|
||||
});
|
||||
applyOutputDefaults(options.output, {
|
||||
context: options.context,
|
||||
targetProperties,
|
||||
isAffectedByBrowserslist: target === undefined ||
|
||||
(typeof target === "string" && target.startsWith("browserslist")) ||
|
||||
(Array.isArray(target) &&
|
||||
target.some(target => target.startsWith("browserslist"))),
|
||||
outputModule: options.experiments.outputModule,
|
||||
entry: options.entry,
|
||||
futureDefaults
|
||||
});
|
||||
applyExternalsPresetsDefaults(options.externalsPresets, {
|
||||
targetProperties
|
||||
});
|
||||
// @ts-expect-error
|
||||
F(options, "externalsType", () => {
|
||||
return options.output.library
|
||||
? options.output.library.type
|
||||
: options.output.module
|
||||
? "module"
|
||||
: "var";
|
||||
});
|
||||
applyNodeDefaults(options.node, { targetProperties });
|
||||
applyOptimizationDefaults(options.optimization, { production, development });
|
||||
options.resolve = (0, cleverMerge_1.cleverMerge)(getResolveDefaults({
|
||||
targetProperties,
|
||||
mode: options.mode
|
||||
}), options.resolve);
|
||||
options.resolveLoader = (0, cleverMerge_1.cleverMerge)(getResolveLoaderDefaults(), options.resolveLoader);
|
||||
};
|
||||
exports.applyRspackOptionsDefaults = applyRspackOptionsDefaults;
|
||||
const applyRspackOptionsBaseDefaults = (options) => {
|
||||
F(options, "context", () => process.cwd());
|
||||
applyInfrastructureLoggingDefaults(options.infrastructureLogging);
|
||||
};
|
||||
exports.applyRspackOptionsBaseDefaults = applyRspackOptionsBaseDefaults;
|
||||
const applyInfrastructureLoggingDefaults = (infrastructureLogging) => {
|
||||
F(infrastructureLogging, "stream", () => process.stderr);
|
||||
const tty = infrastructureLogging.stream.isTTY && process.env.TERM !== "dumb";
|
||||
D(infrastructureLogging, "level", "info");
|
||||
D(infrastructureLogging, "debug", false);
|
||||
D(infrastructureLogging, "colors", tty);
|
||||
D(infrastructureLogging, "appendOnly", !tty);
|
||||
};
|
||||
const applyExperimentsDefaults = (experiments, { cache }) => {
|
||||
D(experiments, "lazyCompilation", false);
|
||||
D(experiments, "asyncWebAssembly", false);
|
||||
D(experiments, "newSplitChunks", true);
|
||||
D(experiments, "css", true); // we not align with webpack about the default value for better DX
|
||||
D(experiments, "topLevelAwait", true);
|
||||
D(experiments, "incrementalRebuild", {});
|
||||
if (typeof experiments.incrementalRebuild === "object") {
|
||||
D(experiments.incrementalRebuild, "make", true);
|
||||
D(experiments.incrementalRebuild, "emitAsset", true);
|
||||
}
|
||||
if (cache === false &&
|
||||
experiments.incrementalRebuild &&
|
||||
experiments.incrementalRebuild.make) {
|
||||
experiments.incrementalRebuild.make = false;
|
||||
// TODO: use logger to warn user enable cache for incrementalRebuild.make
|
||||
}
|
||||
D(experiments, "rspackFuture", {});
|
||||
if (typeof experiments.rspackFuture === "object") {
|
||||
D(experiments.rspackFuture, "newResolver", true);
|
||||
D(experiments.rspackFuture, "newTreeshaking", false);
|
||||
D(experiments.rspackFuture, "disableTransformByDefault", true);
|
||||
}
|
||||
};
|
||||
const applyFeaturesDefaults = (features) => {
|
||||
D(features, 'split_chunks_strategy', {});
|
||||
if (typeof features.split_chunks_strategy === 'object') {
|
||||
D(features.split_chunks_strategy, 'name', '');
|
||||
D(features.split_chunks_strategy, 'topLevelFrameworks', []);
|
||||
}
|
||||
};
|
||||
const applySnapshotDefaults = (snapshot, { production }) => {
|
||||
F(snapshot, "module", () => production
|
||||
? { timestamp: true, hash: true }
|
||||
: { timestamp: true, hash: false });
|
||||
F(snapshot, "resolve", () => production
|
||||
? { timestamp: true, hash: true }
|
||||
: { timestamp: true, hash: false });
|
||||
};
|
||||
const applyJavascriptParserOptionsDefaults = (parserOptions) => {
|
||||
D(parserOptions, "dynamicImportMode", "lazy");
|
||||
};
|
||||
const applyModuleDefaults = (module, { asyncWebAssembly, css, disableTransformByDefault }) => {
|
||||
(0, assertNotNil_1.assertNotNill)(module.parser);
|
||||
F(module.parser, ModuleTypeConstants_1.ASSET_MODULE_TYPE, () => ({}));
|
||||
(0, assertNotNil_1.assertNotNill)(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", () => ({}));
|
||||
(0, assertNotNil_1.assertNotNill)(module.parser.javascript);
|
||||
applyJavascriptParserOptionsDefaults(module.parser.javascript);
|
||||
A(module, "defaultRules", () => {
|
||||
const esm = {
|
||||
type: "javascript/esm",
|
||||
resolve: {
|
||||
byDependency: {
|
||||
esm: {
|
||||
fullySpecified: true
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
const commonjs = {
|
||||
type: "javascript/dynamic"
|
||||
};
|
||||
const rules = [
|
||||
{
|
||||
mimetype: "application/node",
|
||||
type: "javascript/auto"
|
||||
},
|
||||
{
|
||||
test: /\.json$/i,
|
||||
type: "json"
|
||||
},
|
||||
{
|
||||
mimetype: "application/json",
|
||||
type: "json"
|
||||
},
|
||||
{
|
||||
test: /\.mjs$/i,
|
||||
...esm
|
||||
},
|
||||
{
|
||||
test: /\.js$/i,
|
||||
descriptionData: {
|
||||
type: "module"
|
||||
},
|
||||
...esm
|
||||
},
|
||||
{
|
||||
test: /\.cjs$/i,
|
||||
...commonjs
|
||||
},
|
||||
{
|
||||
test: /\.js$/i,
|
||||
descriptionData: {
|
||||
type: "commonjs"
|
||||
},
|
||||
...commonjs
|
||||
},
|
||||
{
|
||||
mimetype: {
|
||||
or: ["text/javascript", "application/javascript"]
|
||||
},
|
||||
...esm
|
||||
}
|
||||
];
|
||||
// TODO: remove in 0.5.0
|
||||
if (!disableTransformByDefault) {
|
||||
rules.push({
|
||||
test: /\.jsx$/i,
|
||||
type: "jsx"
|
||||
}, {
|
||||
test: /\.ts$/i,
|
||||
type: "ts"
|
||||
}, {
|
||||
test: /\.tsx$/i,
|
||||
type: "tsx"
|
||||
});
|
||||
}
|
||||
if (asyncWebAssembly) {
|
||||
const wasm = {
|
||||
type: "webassembly/async",
|
||||
rules: [
|
||||
{
|
||||
descriptionData: {
|
||||
type: "module"
|
||||
},
|
||||
resolve: {
|
||||
fullySpecified: true
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
rules.push({
|
||||
test: /\.wasm$/i,
|
||||
...wasm
|
||||
});
|
||||
rules.push({
|
||||
mimetype: "application/wasm",
|
||||
...wasm
|
||||
});
|
||||
}
|
||||
if (css) {
|
||||
const cssRule = {
|
||||
type: "css",
|
||||
resolve: {
|
||||
fullySpecified: true,
|
||||
preferRelative: true
|
||||
}
|
||||
};
|
||||
const cssModulesRule = {
|
||||
type: "css/module",
|
||||
resolve: {
|
||||
fullySpecified: true
|
||||
}
|
||||
};
|
||||
rules.push({
|
||||
test: /\.css$/i,
|
||||
oneOf: [
|
||||
{
|
||||
test: /\.module\.css$/i,
|
||||
...cssModulesRule
|
||||
},
|
||||
{
|
||||
...cssRule
|
||||
}
|
||||
]
|
||||
});
|
||||
rules.push({
|
||||
mimetype: "text/css+module",
|
||||
...cssModulesRule
|
||||
});
|
||||
rules.push({
|
||||
mimetype: "text/css",
|
||||
...cssRule
|
||||
});
|
||||
}
|
||||
rules.push({
|
||||
dependency: "url",
|
||||
oneOf: [
|
||||
{
|
||||
scheme: /^data$/,
|
||||
type: "asset/inline"
|
||||
},
|
||||
{
|
||||
type: "asset/resource"
|
||||
}
|
||||
]
|
||||
});
|
||||
return rules;
|
||||
});
|
||||
};
|
||||
const applyOutputDefaults = (output, { context, outputModule, targetProperties: tp, isAffectedByBrowserslist, entry, futureDefaults }) => {
|
||||
const getLibraryName = (library) => {
|
||||
const libraryName = typeof library === "object" &&
|
||||
library &&
|
||||
!Array.isArray(library) &&
|
||||
"type" in library
|
||||
? library.name
|
||||
: library;
|
||||
if (Array.isArray(libraryName)) {
|
||||
return libraryName.join(".");
|
||||
}
|
||||
else if (typeof libraryName === "object") {
|
||||
return getLibraryName(libraryName.root);
|
||||
}
|
||||
else if (typeof libraryName === "string") {
|
||||
return libraryName;
|
||||
}
|
||||
return "";
|
||||
};
|
||||
F(output, "uniqueName", () => {
|
||||
const libraryName = getLibraryName(output.library).replace(/^\[(\\*[\w:]+\\*)\](\.)|(\.)\[(\\*[\w:]+\\*)\](?=\.|$)|\[(\\*[\w:]+\\*)\]/g, (m, a, d1, d2, b, c) => {
|
||||
const content = a || b || c;
|
||||
return content.startsWith("\\") && content.endsWith("\\")
|
||||
? `${d2 || ""}[${content.slice(1, -1)}]${d1 || ""}`
|
||||
: "";
|
||||
});
|
||||
if (libraryName)
|
||||
return libraryName;
|
||||
const pkgPath = path_1.default.resolve(context, "package.json");
|
||||
try {
|
||||
const packageInfo = JSON.parse(fs_1.default.readFileSync(pkgPath, "utf-8"));
|
||||
return packageInfo.name || "";
|
||||
}
|
||||
catch (e) {
|
||||
if (e.code !== "ENOENT") {
|
||||
e.message += `\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`;
|
||||
throw e;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
});
|
||||
F(output, "chunkLoadingGlobal", () => Template_1.default.toIdentifier("webpackChunk" + Template_1.default.toIdentifier(output.uniqueName)));
|
||||
F(output, "module", () => !!outputModule);
|
||||
D(output, "filename", output.module ? "[name].mjs" : "[name].js");
|
||||
F(output, "iife", () => !output.module);
|
||||
F(output, "chunkFilename", () => {
|
||||
const filename = 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 "[id].js";
|
||||
});
|
||||
F(output, "cssFilename", () => {
|
||||
const filename = output.filename;
|
||||
if (typeof filename !== "function") {
|
||||
return filename.replace(/\.[mc]?js(\?|$)/, ".css$1");
|
||||
}
|
||||
return "[id].css";
|
||||
});
|
||||
F(output, "cssChunkFilename", () => {
|
||||
const chunkFilename = output.chunkFilename;
|
||||
if (typeof chunkFilename !== "function") {
|
||||
return chunkFilename.replace(/\.[mc]?js(\?|$)/, ".css$1");
|
||||
}
|
||||
return "[id].css";
|
||||
});
|
||||
D(output, "hotUpdateChunkFilename", `[id].[fullhash].hot-update.${output.module ? "mjs" : "js"}`);
|
||||
D(output, "hotUpdateMainFilename", "[runtime].[fullhash].hot-update.json");
|
||||
F(output, "hotUpdateGlobal", () => Template_1.default.toIdentifier("webpackHotUpdate" + Template_1.default.toIdentifier(output.uniqueName)));
|
||||
D(output, "assetModuleFilename", "[hash][ext][query]");
|
||||
D(output, "webassemblyModuleFilename", "[hash].module.wasm");
|
||||
F(output, "path", () => path_1.default.join(process.cwd(), "dist"));
|
||||
D(output, "publicPath", tp && (tp.document || tp.importScripts) ? "auto" : "");
|
||||
D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
|
||||
D(output, "hashDigest", "hex");
|
||||
D(output, "hashDigestLength", futureDefaults ? 16 : 20);
|
||||
D(output, "strictModuleErrorHandling", false);
|
||||
if (output.library) {
|
||||
F(output.library, "type", () => (output.module ? "module" : "var"));
|
||||
}
|
||||
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)
|
||||
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)
|
||||
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, "globalObject", () => {
|
||||
if (tp) {
|
||||
if (tp.global)
|
||||
return "global";
|
||||
if (tp.globalThis)
|
||||
return "globalThis";
|
||||
}
|
||||
return "self";
|
||||
});
|
||||
D(output, "importFunctionName", "import");
|
||||
F(output, "clean", () => !!output.clean);
|
||||
D(output, "crossOriginLoading", false);
|
||||
D(output, "workerPublicPath", "");
|
||||
F(output, "sourceMapFilename", () => {
|
||||
return "[file].map";
|
||||
});
|
||||
F(output, "scriptType", () => (output.module ? "module" : false));
|
||||
const { trustedTypes } = output;
|
||||
if (trustedTypes) {
|
||||
F(trustedTypes, "policyName", () => output.uniqueName.replace(/[^a-zA-Z0-9\-#=_/@.%]+/g, "_") || "webpack");
|
||||
}
|
||||
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);
|
||||
}
|
||||
forEachEntry(desc => {
|
||||
if (desc.library) {
|
||||
enabledLibraryTypes.push(desc.library.type);
|
||||
}
|
||||
});
|
||||
return enabledLibraryTypes;
|
||||
});
|
||||
A(output, "enabledChunkLoadingTypes", () => {
|
||||
const enabledChunkLoadingTypes = new Set();
|
||||
if (output.chunkLoading) {
|
||||
enabledChunkLoadingTypes.add(output.chunkLoading);
|
||||
}
|
||||
if (output.workerChunkLoading) {
|
||||
enabledChunkLoadingTypes.add(output.workerChunkLoading);
|
||||
}
|
||||
forEachEntry(desc => {
|
||||
if (desc.chunkLoading) {
|
||||
enabledChunkLoadingTypes.add(desc.chunkLoading);
|
||||
}
|
||||
});
|
||||
return Array.from(enabledChunkLoadingTypes);
|
||||
});
|
||||
A(output, "enabledWasmLoadingTypes", () => {
|
||||
const enabledWasmLoadingTypes = new Set();
|
||||
if (output.wasmLoading) {
|
||||
enabledWasmLoadingTypes.add(output.wasmLoading);
|
||||
}
|
||||
if (output.workerWasmLoading) {
|
||||
enabledWasmLoadingTypes.add(output.workerWasmLoading);
|
||||
}
|
||||
// forEachEntry(desc => {
|
||||
// if (desc.wasmLoading) {
|
||||
// enabledWasmLoadingTypes.add(desc.wasmLoading);
|
||||
// }
|
||||
// });
|
||||
return Array.from(enabledWasmLoadingTypes);
|
||||
});
|
||||
};
|
||||
const applyExternalsPresetsDefaults = (externalsPresets, { targetProperties }) => {
|
||||
D(externalsPresets, "web", targetProperties && targetProperties.web);
|
||||
D(externalsPresets, "node", targetProperties && targetProperties.node);
|
||||
D(externalsPresets, "electron", targetProperties && targetProperties.electron);
|
||||
D(externalsPresets, "electronMain", targetProperties &&
|
||||
targetProperties.electron &&
|
||||
targetProperties.electronMain);
|
||||
D(externalsPresets, "electronPreload", targetProperties &&
|
||||
targetProperties.electron &&
|
||||
targetProperties.electronPreload);
|
||||
D(externalsPresets, "electronRenderer", targetProperties &&
|
||||
targetProperties.electron &&
|
||||
targetProperties.electronRenderer);
|
||||
};
|
||||
const applyNodeDefaults = (node, { targetProperties }) => {
|
||||
if (node === false)
|
||||
return;
|
||||
F(node, "global", () => {
|
||||
if (targetProperties && targetProperties.global)
|
||||
return false;
|
||||
return "warn";
|
||||
});
|
||||
F(node, "__dirname", () => {
|
||||
if (targetProperties && targetProperties.node)
|
||||
return "eval-only";
|
||||
return "warn-mock";
|
||||
});
|
||||
F(node, "__filename", () => {
|
||||
if (targetProperties && targetProperties.node)
|
||||
return "eval-only";
|
||||
return "warn-mock";
|
||||
});
|
||||
};
|
||||
const applyOptimizationDefaults = (optimization, { production, development }) => {
|
||||
D(optimization, "removeAvailableModules", true);
|
||||
D(optimization, "removeEmptyChunks", true);
|
||||
D(optimization, "mergeDuplicateChunks", true);
|
||||
F(optimization, "moduleIds", () => {
|
||||
if (production)
|
||||
return "deterministic";
|
||||
return "named";
|
||||
});
|
||||
F(optimization, "chunkIds", () => "named");
|
||||
F(optimization, "sideEffects", () => (production ? true : "flag"));
|
||||
D(optimization, "mangleExports", production);
|
||||
D(optimization, "providedExports", true);
|
||||
D(optimization, "usedExports", production);
|
||||
D(optimization, "innerGraph", production);
|
||||
D(optimization, "runtimeChunk", false);
|
||||
D(optimization, "realContentHash", production);
|
||||
D(optimization, "minimize", production);
|
||||
A(optimization, "minimizer", () => [
|
||||
// TODO: enable this when drop support for builtins options
|
||||
// new SwcJsMinimizerPlugin(),
|
||||
// new SwcCssMinimizerPlugin()
|
||||
]);
|
||||
F(optimization, "nodeEnv", () => {
|
||||
if (production)
|
||||
return "production";
|
||||
if (development)
|
||||
return "development";
|
||||
return false;
|
||||
});
|
||||
const { splitChunks } = optimization;
|
||||
if (splitChunks) {
|
||||
// A(splitChunks, "defaultSizeTypes", () =>
|
||||
// css ? ["javascript", "css", "unknown"] : ["javascript", "unknown"]
|
||||
// );
|
||||
D(splitChunks, "hidePathInfo", production);
|
||||
D(splitChunks, "chunks", "async");
|
||||
// D(splitChunks, "usedExports", optimization.usedExports === true);
|
||||
D(splitChunks, "minChunks", 1);
|
||||
F(splitChunks, "minSize", () => (production ? 20000 : 10000));
|
||||
// F(splitChunks, "minRemainingSize", () => (development ? 0 : undefined));
|
||||
// F(splitChunks, "enforceSizeThreshold", () => (production ? 50000 : 30000));
|
||||
F(splitChunks, "maxAsyncRequests", () => (production ? 30 : Infinity));
|
||||
F(splitChunks, "maxInitialRequests", () => (production ? 30 : Infinity));
|
||||
D(splitChunks, "automaticNameDelimiter", "-");
|
||||
const { cacheGroups } = splitChunks;
|
||||
if (cacheGroups) {
|
||||
F(cacheGroups, "default", () => ({
|
||||
idHint: "",
|
||||
reuseExistingChunk: true,
|
||||
minChunks: 2,
|
||||
priority: -20
|
||||
}));
|
||||
F(cacheGroups, "defaultVendors", () => ({
|
||||
idHint: "vendors",
|
||||
reuseExistingChunk: true,
|
||||
test: /[\\/]node_modules[\\/]/i,
|
||||
priority: -10
|
||||
}));
|
||||
}
|
||||
}
|
||||
};
|
||||
const getResolveLoaderDefaults = () => {
|
||||
const resolveOptions = {
|
||||
conditionNames: ["loader", "require", "node"],
|
||||
exportsFields: ["exports"],
|
||||
mainFields: ["loader", "main"],
|
||||
extensions: [".js"],
|
||||
mainFiles: ["index"]
|
||||
};
|
||||
return resolveOptions;
|
||||
};
|
||||
const getResolveDefaults = ({ targetProperties, mode }) => {
|
||||
const conditions = ["webpack"];
|
||||
conditions.push(mode === "development" ? "development" : "production");
|
||||
if (targetProperties) {
|
||||
if (targetProperties.webworker)
|
||||
conditions.push("worker");
|
||||
if (targetProperties.node)
|
||||
conditions.push("node");
|
||||
if (targetProperties.web)
|
||||
conditions.push("browser");
|
||||
if (targetProperties.electron)
|
||||
conditions.push("electron");
|
||||
if (targetProperties.nwjs)
|
||||
conditions.push("nwjs");
|
||||
}
|
||||
const jsExtensions = [".js", ".json", ".wasm", ".tsx", ".ts", ".jsx"];
|
||||
const tp = targetProperties;
|
||||
const browserField = tp && tp.web && (!tp.node || (tp.electron && tp.electronRenderer));
|
||||
const cjsDeps = () => ({
|
||||
browserField,
|
||||
mainFields: browserField ? ["browser", "module", "..."] : ["module", "..."],
|
||||
conditionNames: ["require", "module", "..."],
|
||||
extensions: [...jsExtensions]
|
||||
});
|
||||
const esmDeps = () => ({
|
||||
browserField,
|
||||
mainFields: browserField ? ["browser", "module", "..."] : ["module", "..."],
|
||||
conditionNames: ["import", "module", "..."],
|
||||
extensions: [...jsExtensions]
|
||||
});
|
||||
const resolveOptions = {
|
||||
modules: ["node_modules"],
|
||||
conditionNames: conditions,
|
||||
mainFiles: ["index"],
|
||||
extensions: [],
|
||||
browserField,
|
||||
mainFields: ["main"].filter(Boolean),
|
||||
exportsFields: ["exports"],
|
||||
byDependency: {
|
||||
wasm: esmDeps(),
|
||||
esm: esmDeps(),
|
||||
url: {
|
||||
preferRelative: true
|
||||
},
|
||||
worker: {
|
||||
...esmDeps(),
|
||||
preferRelative: true
|
||||
},
|
||||
commonjs: cjsDeps(),
|
||||
// amd: cjsDeps(),
|
||||
// for backward-compat: loadModule
|
||||
// loader: cjsDeps(),
|
||||
// for backward-compat: Custom Dependency and getResolve without dependencyType
|
||||
unknown: cjsDeps()
|
||||
}
|
||||
};
|
||||
return resolveOptions;
|
||||
};
|
||||
const D = (obj, prop, value) => {
|
||||
if (obj[prop] === undefined) {
|
||||
obj[prop] = value;
|
||||
}
|
||||
};
|
||||
const F = (obj, prop, factory) => {
|
||||
if (obj[prop] === undefined) {
|
||||
obj[prop] = factory();
|
||||
}
|
||||
};
|
||||
const A = (obj, prop, factory) => {
|
||||
const value = obj[prop];
|
||||
if (value === undefined) {
|
||||
obj[prop] = factory();
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
let newArray = undefined;
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const item = value[i];
|
||||
if (item === "...") {
|
||||
if (newArray === undefined) {
|
||||
newArray = value.slice(0, i);
|
||||
// @ts-expect-error
|
||||
obj[prop] = newArray;
|
||||
}
|
||||
const items = factory();
|
||||
if (items !== undefined) {
|
||||
for (const item of items) {
|
||||
newArray.push(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (newArray !== undefined) {
|
||||
newArray.push(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
|
@ -1,299 +0,0 @@
|
|||
"use strict";
|
||||
/**
|
||||
* The following code is modified based on
|
||||
* https://github.com/webpack/webpack/blob/4b4ca3b/lib/config/normalization.js
|
||||
*
|
||||
* MIT Licensed
|
||||
* Author Tobias Koppers @sokra
|
||||
* Copyright (c) JS Foundation and other contributors
|
||||
* https://github.com/webpack/webpack/blob/main/LICENSE
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getNormalizedRspackOptions = void 0;
|
||||
const util_1 = require("../util");
|
||||
const getNormalizedRspackOptions = (config) => {
|
||||
return {
|
||||
features: config.features,
|
||||
ignoreWarnings: config.ignoreWarnings !== undefined
|
||||
? config.ignoreWarnings.map(ignore => {
|
||||
if (typeof ignore === "function") {
|
||||
return ignore;
|
||||
}
|
||||
else {
|
||||
return (warning) => {
|
||||
return ignore.test(warning.message);
|
||||
};
|
||||
}
|
||||
})
|
||||
: undefined,
|
||||
name: config.name,
|
||||
dependencies: config.dependencies,
|
||||
context: config.context,
|
||||
mode: config.mode,
|
||||
entry: config.entry === undefined
|
||||
? { main: {} }
|
||||
: getNormalizedEntryStatic(config.entry),
|
||||
output: nestedConfig(config.output, output => {
|
||||
var _a;
|
||||
const { library } = output;
|
||||
const libraryAsName = library;
|
||||
const libraryBase = typeof library === "object" &&
|
||||
library &&
|
||||
!Array.isArray(library) &&
|
||||
"type" in library
|
||||
? library
|
||||
: libraryAsName || output.libraryTarget
|
||||
? {
|
||||
name: libraryAsName
|
||||
}
|
||||
: undefined;
|
||||
// DEPRECATE: remove this in after version
|
||||
{
|
||||
const ext = "[ext]";
|
||||
const filenames = [
|
||||
"filename",
|
||||
"chunkFilename",
|
||||
"cssFilename",
|
||||
"cssChunkFilename"
|
||||
];
|
||||
const checkFilename = (prop) => {
|
||||
const oldFilename = output[prop];
|
||||
if (typeof oldFilename === "string" && oldFilename.endsWith(ext)) {
|
||||
const newFilename = oldFilename.slice(0, -ext.length) +
|
||||
(prop.includes("css") ? ".css" : ".js");
|
||||
(0, util_1.deprecatedWarn)(`Deprecated: output.${prop} ends with [ext] is now deprecated, please use ${newFilename} instead.`);
|
||||
output[prop] = newFilename;
|
||||
}
|
||||
};
|
||||
filenames.forEach(checkFilename);
|
||||
}
|
||||
return {
|
||||
path: output.path,
|
||||
publicPath: output.publicPath,
|
||||
filename: output.filename,
|
||||
clean: output.clean,
|
||||
chunkFormat: output.chunkFormat,
|
||||
chunkLoading: output.chunkLoading,
|
||||
chunkFilename: output.chunkFilename,
|
||||
crossOriginLoading: output.crossOriginLoading,
|
||||
cssFilename: output.cssFilename,
|
||||
cssChunkFilename: output.cssChunkFilename,
|
||||
hotUpdateMainFilename: output.hotUpdateMainFilename,
|
||||
hotUpdateChunkFilename: output.hotUpdateChunkFilename,
|
||||
hotUpdateGlobal: output.hotUpdateGlobal,
|
||||
assetModuleFilename: output.assetModuleFilename,
|
||||
wasmLoading: output.wasmLoading,
|
||||
enabledChunkLoadingTypes: output.enabledChunkLoadingTypes
|
||||
? [...output.enabledChunkLoadingTypes]
|
||||
: ["..."],
|
||||
enabledWasmLoadingTypes: output.enabledWasmLoadingTypes
|
||||
? [...output.enabledWasmLoadingTypes]
|
||||
: ["..."],
|
||||
webassemblyModuleFilename: output.webassemblyModuleFilename,
|
||||
uniqueName: output.uniqueName,
|
||||
chunkLoadingGlobal: output.chunkLoadingGlobal,
|
||||
enabledLibraryTypes: output.enabledLibraryTypes
|
||||
? [...output.enabledLibraryTypes]
|
||||
: ["..."],
|
||||
globalObject: output.globalObject,
|
||||
importFunctionName: output.importFunctionName,
|
||||
iife: output.iife,
|
||||
module: output.module,
|
||||
sourceMapFilename: output.sourceMapFilename,
|
||||
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
|
||||
},
|
||||
strictModuleErrorHandling: (_a = output.strictModuleErrorHandling) !== null && _a !== void 0 ? _a : output.strictModuleExceptionHandling,
|
||||
trustedTypes: optionalNestedConfig(output.trustedTypes, trustedTypes => {
|
||||
if (trustedTypes === true)
|
||||
return {};
|
||||
if (typeof trustedTypes === "string")
|
||||
return { policyName: trustedTypes };
|
||||
return { ...trustedTypes };
|
||||
}),
|
||||
hashDigest: output.hashDigest,
|
||||
hashDigestLength: output.hashDigestLength,
|
||||
hashFunction: output.hashFunction,
|
||||
hashSalt: output.hashSalt,
|
||||
asyncChunks: output.asyncChunks,
|
||||
workerChunkLoading: output.workerChunkLoading,
|
||||
workerWasmLoading: output.workerWasmLoading,
|
||||
workerPublicPath: output.workerPublicPath,
|
||||
scriptType: output.scriptType
|
||||
};
|
||||
}),
|
||||
resolve: nestedConfig(config.resolve, resolve => ({
|
||||
...resolve
|
||||
})),
|
||||
resolveLoader: nestedConfig(config.resolveLoader, resolve => ({
|
||||
...resolve
|
||||
})),
|
||||
module: nestedConfig(config.module, module => ({
|
||||
parser: keyedNestedConfig(module.parser, cloneObject, {}),
|
||||
generator: keyedNestedConfig(module.generator, cloneObject, {}),
|
||||
defaultRules: optionalNestedArray(module.defaultRules, r => [...r]),
|
||||
rules: nestedArray(module.rules, r => [...r])
|
||||
})),
|
||||
target: config.target,
|
||||
externals: config.externals,
|
||||
externalsType: config.externalsType,
|
||||
externalsPresets: cloneObject(config.externalsPresets),
|
||||
infrastructureLogging: cloneObject(config.infrastructureLogging),
|
||||
devtool: config.devtool,
|
||||
node: nestedConfig(config.node, node => node && {
|
||||
...node
|
||||
}),
|
||||
snapshot: nestedConfig(config.snapshot, snapshot => ({
|
||||
resolve: optionalNestedConfig(snapshot.resolve, resolve => ({
|
||||
timestamp: resolve.timestamp,
|
||||
hash: resolve.hash
|
||||
})),
|
||||
module: optionalNestedConfig(snapshot.module, module => ({
|
||||
timestamp: module.timestamp,
|
||||
hash: module.hash
|
||||
}))
|
||||
})),
|
||||
cache: optionalNestedConfig(config.cache, cache => cache),
|
||||
stats: nestedConfig(config.stats, stats => {
|
||||
if (stats === false) {
|
||||
return {
|
||||
preset: "none"
|
||||
};
|
||||
}
|
||||
if (stats === true) {
|
||||
return {
|
||||
preset: "normal"
|
||||
};
|
||||
}
|
||||
if (typeof stats === "string") {
|
||||
return {
|
||||
preset: stats
|
||||
};
|
||||
}
|
||||
return {
|
||||
...stats
|
||||
};
|
||||
}),
|
||||
optimization: nestedConfig(config.optimization, optimization => {
|
||||
return {
|
||||
...optimization,
|
||||
runtimeChunk: getNormalizedOptimizationRuntimeChunk(optimization.runtimeChunk),
|
||||
splitChunks: nestedConfig(optimization.splitChunks, splitChunks => splitChunks && {
|
||||
...splitChunks,
|
||||
cacheGroups: cloneObject(splitChunks.cacheGroups)
|
||||
})
|
||||
};
|
||||
}),
|
||||
plugins: nestedArray(config.plugins, p => [...p]),
|
||||
experiments: nestedConfig(config.experiments, experiments => ({
|
||||
...experiments,
|
||||
incrementalRebuild: optionalNestedConfig(experiments.incrementalRebuild, options => (options === true ? {} : options))
|
||||
})),
|
||||
watch: config.watch,
|
||||
watchOptions: cloneObject(config.watchOptions),
|
||||
devServer: config.devServer,
|
||||
profile: config.profile,
|
||||
builtins: nestedConfig(config.builtins, builtins => ({
|
||||
...builtins
|
||||
}))
|
||||
};
|
||||
};
|
||||
exports.getNormalizedRspackOptions = getNormalizedRspackOptions;
|
||||
const getNormalizedEntryStatic = (entry) => {
|
||||
if (typeof entry === "string") {
|
||||
return {
|
||||
main: {
|
||||
import: [entry]
|
||||
}
|
||||
};
|
||||
}
|
||||
if (Array.isArray(entry)) {
|
||||
return {
|
||||
main: {
|
||||
import: entry
|
||||
}
|
||||
};
|
||||
}
|
||||
const result = {};
|
||||
for (const key of Object.keys(entry)) {
|
||||
const value = entry[key];
|
||||
if (typeof value === "string") {
|
||||
result[key] = {
|
||||
import: [value]
|
||||
};
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
result[key] = {
|
||||
import: value
|
||||
};
|
||||
}
|
||||
else {
|
||||
result[key] = {
|
||||
import: Array.isArray(value.import) ? value.import : [value.import],
|
||||
runtime: value.runtime,
|
||||
publicPath: value.publicPath,
|
||||
baseUri: value.baseUri,
|
||||
chunkLoading: value.chunkLoading,
|
||||
asyncChunks: value.asyncChunks,
|
||||
filename: value.filename,
|
||||
library: value.library
|
||||
};
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
const getNormalizedOptimizationRuntimeChunk = (runtimeChunk) => {
|
||||
if (runtimeChunk === undefined)
|
||||
return undefined;
|
||||
if (runtimeChunk === false)
|
||||
return false;
|
||||
if (runtimeChunk === "single") {
|
||||
return {
|
||||
name: () => "runtime"
|
||||
};
|
||||
}
|
||||
if (runtimeChunk === true || runtimeChunk === "multiple") {
|
||||
return {
|
||||
name: (entrypoint) => `runtime~${entrypoint.name}`
|
||||
};
|
||||
}
|
||||
const { name } = runtimeChunk;
|
||||
const opts = {
|
||||
name: typeof name === "function" ? name : () => name
|
||||
};
|
||||
return opts;
|
||||
};
|
||||
const nestedConfig = (value, fn) => value === undefined ? fn({}) : fn(value);
|
||||
const optionalNestedConfig = (value, fn) => (value === undefined ? undefined : fn(value));
|
||||
const nestedArray = (value, fn) => Array.isArray(value) ? fn(value) : fn([]);
|
||||
const optionalNestedArray = (value, fn) => (Array.isArray(value) ? fn(value) : undefined);
|
||||
const cloneObject = (value) => ({ ...value });
|
||||
const keyedNestedConfig = (value, fn, customKeys) => {
|
||||
const result = value === undefined
|
||||
? {}
|
||||
: Object.keys(value).reduce((obj, key) => ((obj[key] = (customKeys && key in customKeys ? customKeys[key] : fn)(value[key])),
|
||||
obj), {});
|
||||
if (customKeys) {
|
||||
for (const key of Object.keys(customKeys)) {
|
||||
if (!(key in result)) {
|
||||
result[key] = customKeys[key]({});
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
|
@ -1,738 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.rspackOptions = exports.externalsType = void 0;
|
||||
const zod_1 = require("zod");
|
||||
const util_1 = require("../util");
|
||||
const Module_1 = require("../Module");
|
||||
//#region Name
|
||||
const name = zod_1.z.string();
|
||||
//#endregion
|
||||
//#region Dependencies
|
||||
const dependencies = zod_1.z.array(name);
|
||||
//#endregion
|
||||
//#region Context
|
||||
const context = zod_1.z.string();
|
||||
//#endregion
|
||||
//#region Mode
|
||||
const mode = zod_1.z.enum(["development", "production", "none"]);
|
||||
//#endregion
|
||||
//#region Entry
|
||||
const rawPublicPath = zod_1.z.string();
|
||||
const publicPath = zod_1.z.literal("auto").or(rawPublicPath);
|
||||
const baseUri = zod_1.z.string();
|
||||
const chunkLoadingType = zod_1.z
|
||||
.enum(["jsonp", "import-scripts", "require", "async-node", "import"])
|
||||
.or(zod_1.z.string());
|
||||
const chunkLoading = zod_1.z.literal(false).or(chunkLoadingType);
|
||||
const asyncChunks = zod_1.z.boolean();
|
||||
const wasmLoadingType = zod_1.z
|
||||
.enum(["fetch-streaming", "fetch", "async-node"])
|
||||
.or(zod_1.z.string());
|
||||
const wasmLoading = zod_1.z.literal(false).or(wasmLoadingType);
|
||||
const scriptType = zod_1.z.enum(["text/javascript", "module"]).or(zod_1.z.literal(false));
|
||||
const libraryCustomUmdObject = zod_1.z.strictObject({
|
||||
amd: zod_1.z.string().optional(),
|
||||
commonjs: zod_1.z.string().optional(),
|
||||
root: zod_1.z.string().or(zod_1.z.array(zod_1.z.string())).optional()
|
||||
});
|
||||
const libraryName = zod_1.z
|
||||
.string()
|
||||
.or(zod_1.z.array(zod_1.z.string()))
|
||||
.or(libraryCustomUmdObject);
|
||||
const libraryCustomUmdCommentObject = zod_1.z.strictObject({
|
||||
amd: zod_1.z.string().optional(),
|
||||
commonjs: zod_1.z.string().optional(),
|
||||
commonjs2: zod_1.z.string().optional(),
|
||||
root: zod_1.z.string().optional()
|
||||
});
|
||||
const amdContainer = zod_1.z.string();
|
||||
const auxiliaryComment = zod_1.z.string().or(libraryCustomUmdCommentObject);
|
||||
const libraryExport = zod_1.z.string().or(zod_1.z.array(zod_1.z.string()));
|
||||
const libraryType = zod_1.z
|
||||
.enum([
|
||||
"var",
|
||||
"module",
|
||||
"assign",
|
||||
"assign-properties",
|
||||
"this",
|
||||
"window",
|
||||
"self",
|
||||
"global",
|
||||
"commonjs",
|
||||
"commonjs2",
|
||||
"commonjs-module",
|
||||
"commonjs-static",
|
||||
"amd",
|
||||
"amd-require",
|
||||
"umd",
|
||||
"umd2",
|
||||
"jsonp",
|
||||
"system"
|
||||
])
|
||||
.or(zod_1.z.string());
|
||||
const umdNamedDefine = zod_1.z.boolean();
|
||||
const libraryOptions = zod_1.z.strictObject({
|
||||
amdContainer: amdContainer.optional(),
|
||||
auxiliaryComment: auxiliaryComment.optional(),
|
||||
export: libraryExport.optional(),
|
||||
name: libraryName.optional(),
|
||||
type: libraryType,
|
||||
umdNamedDefine: umdNamedDefine.optional()
|
||||
});
|
||||
const library = libraryName.or(libraryOptions).optional();
|
||||
const filenameTemplate = zod_1.z.string();
|
||||
const filename = filenameTemplate;
|
||||
const entryFilename = filenameTemplate;
|
||||
const entryRuntime = zod_1.z.literal(false).or(zod_1.z.string());
|
||||
const entryItem = zod_1.z.string().or(zod_1.z.array(zod_1.z.string()));
|
||||
const entryDescription = zod_1.z.strictObject({
|
||||
import: entryItem,
|
||||
runtime: entryRuntime.optional(),
|
||||
publicPath: publicPath.optional(),
|
||||
baseUri: baseUri.optional(),
|
||||
chunkLoading: chunkLoading.optional(),
|
||||
asyncChunks: asyncChunks.optional(),
|
||||
wasmLoading: wasmLoading.optional(),
|
||||
filename: entryFilename.optional(),
|
||||
library: libraryOptions.optional()
|
||||
});
|
||||
const entryUnnamed = entryItem;
|
||||
const entryObject = zod_1.z.record(entryItem.or(entryDescription));
|
||||
const entryStatic = entryObject.or(entryUnnamed);
|
||||
const entry = entryStatic;
|
||||
//#endregion
|
||||
//#region Output
|
||||
const path = zod_1.z.string();
|
||||
const assetModuleFilename = zod_1.z.string();
|
||||
const webassemblyModuleFilename = zod_1.z.string();
|
||||
const chunkFilename = filenameTemplate;
|
||||
const crossOriginLoading = zod_1.z
|
||||
.literal(false)
|
||||
.or(zod_1.z.enum(["anonymous", "use-credentials"]));
|
||||
const cssFilename = filenameTemplate;
|
||||
const cssChunkFilename = filenameTemplate;
|
||||
const hotUpdateChunkFilename = filenameTemplate;
|
||||
const hotUpdateMainFilename = filenameTemplate;
|
||||
const hotUpdateGlobal = zod_1.z.string();
|
||||
const uniqueName = zod_1.z.string();
|
||||
const chunkLoadingGlobal = zod_1.z.string();
|
||||
const enabledLibraryTypes = zod_1.z.array(libraryType);
|
||||
const clean = zod_1.z.boolean();
|
||||
const outputModule = zod_1.z.boolean();
|
||||
const strictModuleExceptionHandling = zod_1.z.boolean();
|
||||
const strictModuleErrorHandling = zod_1.z.boolean();
|
||||
const globalObject = zod_1.z.string();
|
||||
const enabledWasmLoadingTypes = zod_1.z.array(wasmLoadingType);
|
||||
const importFunctionName = zod_1.z.string();
|
||||
const iife = zod_1.z.boolean();
|
||||
const enabledChunkLoadingTypes = zod_1.z.array(chunkLoadingType);
|
||||
const chunkFormat = zod_1.z.literal(false).or(zod_1.z.string());
|
||||
const workerPublicPath = zod_1.z.string();
|
||||
const trustedTypes = zod_1.z.strictObject({
|
||||
policyName: zod_1.z.string().optional()
|
||||
});
|
||||
const hashDigest = zod_1.z.string();
|
||||
const hashDigestLength = zod_1.z.number();
|
||||
const hashFunction = zod_1.z.string();
|
||||
const hashSalt = zod_1.z.string();
|
||||
const sourceMapFilename = zod_1.z.string();
|
||||
const output = zod_1.z.strictObject({
|
||||
path: path.optional(),
|
||||
clean: clean.optional(),
|
||||
publicPath: publicPath.optional(),
|
||||
filename: filename.optional(),
|
||||
chunkFilename: chunkFilename.optional(),
|
||||
crossOriginLoading: crossOriginLoading.optional(),
|
||||
cssFilename: cssFilename.optional(),
|
||||
cssChunkFilename: cssChunkFilename.optional(),
|
||||
hotUpdateMainFilename: hotUpdateMainFilename.optional(),
|
||||
hotUpdateChunkFilename: hotUpdateChunkFilename.optional(),
|
||||
hotUpdateGlobal: hotUpdateGlobal.optional(),
|
||||
assetModuleFilename: assetModuleFilename.optional(),
|
||||
uniqueName: uniqueName.optional(),
|
||||
chunkLoadingGlobal: chunkLoadingGlobal.optional(),
|
||||
enabledLibraryTypes: enabledLibraryTypes.optional(),
|
||||
library: library.optional(),
|
||||
libraryExport: libraryExport.optional(),
|
||||
libraryTarget: libraryType.optional(),
|
||||
umdNamedDefine: umdNamedDefine.optional(),
|
||||
amdContainer: amdContainer.optional(),
|
||||
auxiliaryComment: auxiliaryComment.optional(),
|
||||
module: outputModule.optional(),
|
||||
strictModuleExceptionHandling: strictModuleExceptionHandling.optional(),
|
||||
strictModuleErrorHandling: strictModuleErrorHandling.optional(),
|
||||
globalObject: globalObject.optional(),
|
||||
importFunctionName: importFunctionName.optional(),
|
||||
iife: iife.optional(),
|
||||
wasmLoading: wasmLoading.optional(),
|
||||
enabledWasmLoadingTypes: enabledWasmLoadingTypes.optional(),
|
||||
webassemblyModuleFilename: webassemblyModuleFilename.optional(),
|
||||
chunkFormat: chunkFormat.optional(),
|
||||
chunkLoading: chunkLoading.optional(),
|
||||
enabledChunkLoadingTypes: enabledChunkLoadingTypes.optional(),
|
||||
trustedTypes: zod_1.z.literal(true).or(zod_1.z.string()).or(trustedTypes).optional(),
|
||||
sourceMapFilename: sourceMapFilename.optional(),
|
||||
hashDigest: hashDigest.optional(),
|
||||
hashDigestLength: hashDigestLength.optional(),
|
||||
hashFunction: hashFunction.optional(),
|
||||
hashSalt: hashSalt.optional(),
|
||||
asyncChunks: asyncChunks.optional(),
|
||||
workerChunkLoading: chunkLoading.optional(),
|
||||
workerWasmLoading: wasmLoading.optional(),
|
||||
workerPublicPath: workerPublicPath.optional(),
|
||||
scriptType: scriptType.optional()
|
||||
});
|
||||
//#endregion
|
||||
//#region Resolve
|
||||
const resolveAlias = zod_1.z.record(zod_1.z
|
||||
.literal(false)
|
||||
.or(zod_1.z.string())
|
||||
.or(zod_1.z.array(zod_1.z.string().or(zod_1.z.literal(false)))));
|
||||
const resolveTsconfig = zod_1.z.strictObject({
|
||||
configFile: zod_1.z.string(),
|
||||
references: zod_1.z.array(zod_1.z.string()).or(zod_1.z.literal("auto")).optional()
|
||||
});
|
||||
const baseResolveOptions = zod_1.z.strictObject({
|
||||
alias: resolveAlias.optional(),
|
||||
/**
|
||||
* This is `aliasField: ["browser"]` in webpack, because no one
|
||||
* uses aliasField other than "browser". ---@bvanjoi
|
||||
*/
|
||||
browserField: zod_1.z.boolean().optional(),
|
||||
conditionNames: zod_1.z.array(zod_1.z.string()).optional(),
|
||||
extensions: zod_1.z.array(zod_1.z.string()).optional(),
|
||||
fallback: resolveAlias.optional(),
|
||||
mainFields: zod_1.z.array(zod_1.z.string()).optional(),
|
||||
mainFiles: zod_1.z.array(zod_1.z.string()).optional(),
|
||||
modules: zod_1.z.array(zod_1.z.string()).optional(),
|
||||
preferRelative: zod_1.z.boolean().optional(),
|
||||
tsConfigPath: zod_1.z.string().optional(),
|
||||
tsConfig: resolveTsconfig.optional(),
|
||||
fullySpecified: zod_1.z.boolean().optional(),
|
||||
exportsFields: zod_1.z.array(zod_1.z.string()).optional(),
|
||||
extensionAlias: zod_1.z.record(zod_1.z.string().or(zod_1.z.array(zod_1.z.string()))).optional()
|
||||
});
|
||||
const resolveOptions = baseResolveOptions.extend({
|
||||
byDependency: zod_1.z.lazy(() => zod_1.z.record(resolveOptions)).optional()
|
||||
});
|
||||
const resolve = resolveOptions;
|
||||
//#endregion
|
||||
//#region Module
|
||||
const baseRuleSetCondition = zod_1.z
|
||||
.instanceof(RegExp)
|
||||
.or(zod_1.z.string())
|
||||
.or(zod_1.z.function().args(zod_1.z.string()).returns(zod_1.z.boolean()));
|
||||
const ruleSetCondition = baseRuleSetCondition
|
||||
.or(zod_1.z.lazy(() => ruleSetConditions))
|
||||
.or(zod_1.z.lazy(() => ruleSetLogicalConditions));
|
||||
const ruleSetConditions = zod_1.z.lazy(() => zod_1.z.array(ruleSetCondition));
|
||||
const ruleSetLogicalConditions = zod_1.z.strictObject({
|
||||
and: ruleSetConditions.optional(),
|
||||
or: ruleSetConditions.optional(),
|
||||
not: ruleSetConditions.optional()
|
||||
});
|
||||
const ruleSetLoader = zod_1.z.string();
|
||||
const ruleSetLoaderOptions = zod_1.z.string().or(zod_1.z.record(zod_1.z.any()));
|
||||
const ruleSetLoaderWithOptions = zod_1.z.strictObject({
|
||||
ident: zod_1.z.string().optional(),
|
||||
loader: ruleSetLoader,
|
||||
options: ruleSetLoaderOptions.optional()
|
||||
});
|
||||
const ruleSetUseItem = ruleSetLoader.or(ruleSetLoaderWithOptions);
|
||||
const ruleSetUse = ruleSetUseItem
|
||||
.or(ruleSetUseItem.array())
|
||||
.or(zod_1.z.function().args(zod_1.z.custom()).returns(ruleSetUseItem.array()));
|
||||
const baseRuleSetRule = zod_1.z.strictObject({
|
||||
test: ruleSetCondition.optional(),
|
||||
exclude: ruleSetCondition.optional(),
|
||||
include: ruleSetCondition.optional(),
|
||||
issuer: ruleSetCondition.optional(),
|
||||
dependency: ruleSetCondition.optional(),
|
||||
resource: ruleSetCondition.optional(),
|
||||
resourceFragment: ruleSetCondition.optional(),
|
||||
resourceQuery: ruleSetCondition.optional(),
|
||||
scheme: ruleSetCondition.optional(),
|
||||
mimetype: ruleSetCondition.optional(),
|
||||
descriptionData: zod_1.z.record(ruleSetCondition).optional(),
|
||||
type: zod_1.z.string().optional(),
|
||||
loader: ruleSetLoader.optional(),
|
||||
options: ruleSetLoaderOptions.optional(),
|
||||
use: ruleSetUse.optional(),
|
||||
parser: zod_1.z.record(zod_1.z.any()).optional(),
|
||||
generator: zod_1.z.record(zod_1.z.any()).optional(),
|
||||
resolve: resolveOptions.optional(),
|
||||
sideEffects: zod_1.z.boolean().optional(),
|
||||
enforce: zod_1.z.literal("pre").or(zod_1.z.literal("post")).optional()
|
||||
});
|
||||
const ruleSetRule = baseRuleSetRule.extend({
|
||||
oneOf: zod_1.z.lazy(() => ruleSetRule.array()).optional(),
|
||||
rules: zod_1.z.lazy(() => ruleSetRule.array()).optional()
|
||||
});
|
||||
const ruleSetRules = zod_1.z.array(zod_1.z.literal("...").or(ruleSetRule));
|
||||
const assetParserDataUrlOptions = zod_1.z.strictObject({
|
||||
maxSize: zod_1.z.number().optional()
|
||||
});
|
||||
const assetParserDataUrl = assetParserDataUrlOptions;
|
||||
const assetParserOptions = zod_1.z.strictObject({
|
||||
dataUrlCondition: assetParserDataUrl.optional()
|
||||
});
|
||||
//TODO: "weak", "lazy-once"
|
||||
const dynamicImportMode = zod_1.z.enum(["eager", "lazy"]);
|
||||
const javascriptParserOptions = zod_1.z.strictObject({
|
||||
dynamicImportMode: dynamicImportMode.optional()
|
||||
});
|
||||
const parserOptionsByModuleTypeKnown = zod_1.z.strictObject({
|
||||
asset: assetParserOptions.optional(),
|
||||
javascript: javascriptParserOptions.optional()
|
||||
});
|
||||
const parserOptionsByModuleTypeUnknown = zod_1.z.record(zod_1.z.record(zod_1.z.any()));
|
||||
const parserOptionsByModuleType = parserOptionsByModuleTypeKnown.or(parserOptionsByModuleTypeUnknown);
|
||||
const assetGeneratorDataUrlOptions = zod_1.z.strictObject({
|
||||
encoding: zod_1.z.literal(false).or(zod_1.z.literal("base64")).optional(),
|
||||
mimetype: zod_1.z.string().optional()
|
||||
});
|
||||
const assetGeneratorDataUrl = assetGeneratorDataUrlOptions;
|
||||
const assetInlineGeneratorOptions = zod_1.z.strictObject({
|
||||
dataUrl: assetGeneratorDataUrl.optional()
|
||||
});
|
||||
const assetResourceGeneratorOptions = zod_1.z.strictObject({
|
||||
filename: filenameTemplate.optional(),
|
||||
publicPath: publicPath.optional()
|
||||
});
|
||||
const assetGeneratorOptions = assetInlineGeneratorOptions.merge(assetResourceGeneratorOptions);
|
||||
const generatorOptionsByModuleTypeKnown = zod_1.z.strictObject({
|
||||
asset: assetGeneratorOptions.optional(),
|
||||
"asset/inline": assetInlineGeneratorOptions.optional(),
|
||||
"asset/resource": assetResourceGeneratorOptions.optional()
|
||||
});
|
||||
const generatorOptionsByModuleTypeUnknown = zod_1.z.record(zod_1.z.record(zod_1.z.any()));
|
||||
const generatorOptionsByModuleType = generatorOptionsByModuleTypeKnown.or(generatorOptionsByModuleTypeUnknown);
|
||||
const moduleOptions = zod_1.z.strictObject({
|
||||
defaultRules: ruleSetRules.optional(),
|
||||
rules: ruleSetRules.optional(),
|
||||
parser: parserOptionsByModuleType.optional(),
|
||||
generator: generatorOptionsByModuleType.optional()
|
||||
});
|
||||
//#endregion
|
||||
//#region Target
|
||||
const allowTarget = zod_1.z
|
||||
.enum([
|
||||
"web",
|
||||
"webworker",
|
||||
"es3",
|
||||
"es5",
|
||||
"es2015",
|
||||
"es2016",
|
||||
"es2017",
|
||||
"es2018",
|
||||
"es2019",
|
||||
"es2020",
|
||||
"es2021",
|
||||
"es2022",
|
||||
"browserslist"
|
||||
])
|
||||
.or(zod_1.z.literal("node"))
|
||||
.or(zod_1.z.literal("async-node"))
|
||||
.or(zod_1.z.custom(value => typeof value === "string" && /^node\d+$/.test(value)))
|
||||
.or(zod_1.z.custom(value => typeof value === "string" && /^async-node\d+$/.test(value)))
|
||||
.or(zod_1.z.custom(value => typeof value === "string" && /^node\d+\.\d+$/.test(value)))
|
||||
.or(zod_1.z.custom(value => typeof value === "string" && /^async-node\d+\.\d+$/.test(value)))
|
||||
.or(zod_1.z.literal("electron-main"))
|
||||
.or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+-main$/.test(value)))
|
||||
.or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+\.\d+-main$/.test(value)))
|
||||
.or(zod_1.z.literal("electron-renderer"))
|
||||
.or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+-renderer$/.test(value)))
|
||||
.or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+\.\d+-renderer$/.test(value)))
|
||||
.or(zod_1.z.literal("electron-preload"))
|
||||
.or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+-preload$/.test(value)))
|
||||
.or(zod_1.z.custom(value => typeof value === "string" && /^electron\d+\.\d+-preload$/.test(value)));
|
||||
const target = zod_1.z.literal(false).or(allowTarget).or(allowTarget.array());
|
||||
//#endregion
|
||||
//#region ExternalsType
|
||||
exports.externalsType = zod_1.z.enum([
|
||||
"var",
|
||||
"module",
|
||||
"assign",
|
||||
"this",
|
||||
"window",
|
||||
"self",
|
||||
"global",
|
||||
"commonjs",
|
||||
"commonjs2",
|
||||
"commonjs-module",
|
||||
"commonjs-static",
|
||||
"amd",
|
||||
"amd-require",
|
||||
"umd",
|
||||
"umd2",
|
||||
"jsonp",
|
||||
"system",
|
||||
"promise",
|
||||
"import",
|
||||
"script",
|
||||
"node-commonjs"
|
||||
]);
|
||||
//#endregion
|
||||
//#region Externals
|
||||
const externalItemValue = zod_1.z
|
||||
.string()
|
||||
.or(zod_1.z.boolean())
|
||||
.or(zod_1.z.string().array().min(1))
|
||||
.or(zod_1.z.record(zod_1.z.string().or(zod_1.z.string().array())));
|
||||
const externalItemObjectUnknown = zod_1.z.record(externalItemValue);
|
||||
const externalItemFunctionData = zod_1.z.strictObject({
|
||||
context: zod_1.z.string().optional(),
|
||||
dependencyType: zod_1.z.string().optional(),
|
||||
request: zod_1.z.string().optional()
|
||||
});
|
||||
const externalItem = zod_1.z
|
||||
.string()
|
||||
.or(zod_1.z.instanceof(RegExp))
|
||||
.or(externalItemObjectUnknown)
|
||||
.or(zod_1.z
|
||||
.function()
|
||||
.args(externalItemFunctionData, zod_1.z
|
||||
.function()
|
||||
.args(zod_1.z.instanceof(Error).optional(), externalItemValue.optional(), exports.externalsType.optional())
|
||||
.returns(zod_1.z.void())))
|
||||
.or(zod_1.z
|
||||
.function()
|
||||
.args(externalItemFunctionData)
|
||||
.returns(zod_1.z.promise(externalItemValue)));
|
||||
const externals = externalItem.array().or(externalItem);
|
||||
//#endregion
|
||||
//#region ExternalsPresets
|
||||
const externalsPresets = zod_1.z.strictObject({
|
||||
node: zod_1.z.boolean().optional(),
|
||||
web: zod_1.z.boolean().optional(),
|
||||
webAsync: zod_1.z.boolean().optional(),
|
||||
electron: zod_1.z.boolean().optional(),
|
||||
electronMain: zod_1.z.boolean().optional(),
|
||||
electronPreload: zod_1.z.boolean().optional(),
|
||||
electronRenderer: zod_1.z.boolean().optional()
|
||||
});
|
||||
//#endregion
|
||||
//#region InfrastructureLogging
|
||||
const filterItemTypes = zod_1.z
|
||||
.instanceof(RegExp)
|
||||
.or(zod_1.z.string())
|
||||
.or(zod_1.z.function().args(zod_1.z.string()).returns(zod_1.z.boolean()));
|
||||
const filterTypes = filterItemTypes.array().or(filterItemTypes);
|
||||
const infrastructureLogging = zod_1.z.strictObject({
|
||||
appendOnly: zod_1.z.boolean().optional(),
|
||||
colors: zod_1.z.boolean().optional(),
|
||||
console: zod_1.z.custom().optional(),
|
||||
debug: zod_1.z.boolean().or(filterTypes).optional(),
|
||||
level: zod_1.z.enum(["none", "error", "warn", "info", "log", "verbose"]).optional(),
|
||||
stream: zod_1.z.custom().optional()
|
||||
});
|
||||
//#endregion
|
||||
//#region DevTool
|
||||
const devTool = zod_1.z
|
||||
.literal(false)
|
||||
.or(zod_1.z.enum([
|
||||
"cheap-source-map",
|
||||
"cheap-module-source-map",
|
||||
"source-map",
|
||||
"inline-cheap-source-map",
|
||||
"inline-cheap-module-source-map",
|
||||
"inline-source-map",
|
||||
"inline-nosources-cheap-module-source-map",
|
||||
"inline-nosources-source-map",
|
||||
"nosources-cheap-source-map",
|
||||
"nosources-cheap-module-source-map",
|
||||
"nosources-source-map",
|
||||
"hidden-nosources-cheap-source-map",
|
||||
"hidden-nosources-cheap-module-source-map",
|
||||
"hidden-nosources-source-map",
|
||||
"hidden-cheap-source-map",
|
||||
"hidden-cheap-module-source-map",
|
||||
"hidden-source-map",
|
||||
"eval-cheap-source-map",
|
||||
"eval-cheap-module-source-map",
|
||||
"eval-source-map",
|
||||
"eval-nosources-cheap-source-map",
|
||||
"eval-nosources-cheap-module-source-map",
|
||||
"eval-nosources-source-map"
|
||||
]));
|
||||
//#endregion
|
||||
//#region Node
|
||||
const nodeOptions = zod_1.z.strictObject({
|
||||
__dirname: zod_1.z
|
||||
.boolean()
|
||||
.or(zod_1.z.enum(["warn-mock", "mock", "eval-only"]))
|
||||
.optional(),
|
||||
__filename: zod_1.z
|
||||
.boolean()
|
||||
.or(zod_1.z.enum(["warn-mock", "mock", "eval-only"]))
|
||||
.optional(),
|
||||
global: zod_1.z.boolean().or(zod_1.z.literal("warn")).optional()
|
||||
});
|
||||
const node = zod_1.z.literal(false).or(nodeOptions);
|
||||
//#endregion
|
||||
//#region Snapshot
|
||||
const snapshotOptions = zod_1.z.strictObject({
|
||||
module: zod_1.z
|
||||
.strictObject({
|
||||
hash: zod_1.z.boolean().optional(),
|
||||
timestamp: zod_1.z.boolean().optional()
|
||||
})
|
||||
.optional(),
|
||||
resolve: zod_1.z
|
||||
.strictObject({
|
||||
hash: zod_1.z.boolean().optional(),
|
||||
timestamp: zod_1.z.boolean().optional()
|
||||
})
|
||||
.optional()
|
||||
});
|
||||
//#endregion
|
||||
//#region Cache
|
||||
const cacheOptions = zod_1.z.boolean();
|
||||
//#endregion
|
||||
//#region Stats
|
||||
const statsOptions = zod_1.z.strictObject({
|
||||
all: zod_1.z.boolean().optional(),
|
||||
preset: zod_1.z
|
||||
.enum(["normal", "none", "verbose", "errors-only", "errors-warnings"])
|
||||
.optional(),
|
||||
assets: zod_1.z.boolean().optional(),
|
||||
chunks: zod_1.z.boolean().optional(),
|
||||
modules: zod_1.z.boolean().optional(),
|
||||
entrypoints: zod_1.z.boolean().optional(),
|
||||
chunkGroups: zod_1.z.boolean().optional(),
|
||||
warnings: zod_1.z.boolean().optional(),
|
||||
warningsCount: zod_1.z.boolean().optional(),
|
||||
errors: zod_1.z.boolean().optional(),
|
||||
errorsCount: zod_1.z.boolean().optional(),
|
||||
colors: zod_1.z.boolean().optional(),
|
||||
hash: zod_1.z.boolean().optional(),
|
||||
version: zod_1.z.boolean().optional(),
|
||||
reasons: zod_1.z.boolean().optional(),
|
||||
publicPath: zod_1.z.boolean().optional(),
|
||||
outputPath: zod_1.z.boolean().optional(),
|
||||
chunkModules: zod_1.z.boolean().optional(),
|
||||
chunkRelations: zod_1.z.boolean().optional(),
|
||||
ids: zod_1.z.boolean().optional(),
|
||||
timings: zod_1.z.boolean().optional(),
|
||||
builtAt: zod_1.z.boolean().optional(),
|
||||
moduleAssets: zod_1.z.boolean().optional(),
|
||||
modulesSpace: zod_1.z.number().optional(),
|
||||
nestedModules: zod_1.z.boolean().optional(),
|
||||
source: zod_1.z.boolean().optional(),
|
||||
logging: zod_1.z
|
||||
.enum(["none", "error", "warn", "info", "log", "verbose"])
|
||||
.or(zod_1.z.boolean())
|
||||
.optional(),
|
||||
loggingDebug: zod_1.z.boolean().or(filterTypes).optional(),
|
||||
loggingTrace: zod_1.z.boolean().optional(),
|
||||
runtimeModules: zod_1.z.boolean().optional()
|
||||
});
|
||||
const statsValue = zod_1.z
|
||||
.enum(["none", "errors-only", "errors-warnings", "normal", "verbose"])
|
||||
.or(zod_1.z.boolean())
|
||||
.or(statsOptions);
|
||||
const plugin = zod_1.z.union([
|
||||
zod_1.z.custom(),
|
||||
zod_1.z.custom()
|
||||
]);
|
||||
const plugins = plugin.array();
|
||||
//#endregion
|
||||
//#region Optimization
|
||||
const optimizationRuntimeChunk = zod_1.z
|
||||
.enum(["single", "multiple"])
|
||||
.or(zod_1.z.boolean())
|
||||
.or(zod_1.z.strictObject({
|
||||
name: zod_1.z
|
||||
.string()
|
||||
.or(zod_1.z.function().returns(zod_1.z.string().or(zod_1.z.undefined())))
|
||||
.optional()
|
||||
}));
|
||||
const optimizationSplitChunksNameFunction = zod_1.z.function().args(zod_1.z.instanceof(Module_1.Module).optional()
|
||||
// FIXME: z.array(z.instanceof(Chunk)).optional(), z.string()
|
||||
// FIXME: Chunk[], cacheChunkKey
|
||||
);
|
||||
const optimizationSplitChunksName = zod_1.z
|
||||
.string()
|
||||
.or(zod_1.z.literal(false))
|
||||
.or(optimizationSplitChunksNameFunction);
|
||||
const optimizationSplitChunksChunks = zod_1.z
|
||||
.enum(["initial", "async", "all"])
|
||||
.or(zod_1.z.instanceof(RegExp));
|
||||
const optimizationSplitChunksSizes = zod_1.z.number();
|
||||
const sharedOptimizationSplitChunksCacheGroup = {
|
||||
chunks: optimizationSplitChunksChunks.optional(),
|
||||
minChunks: zod_1.z.number().optional(),
|
||||
name: optimizationSplitChunksName.optional(),
|
||||
minSize: optimizationSplitChunksSizes.optional(),
|
||||
maxSize: optimizationSplitChunksSizes.optional(),
|
||||
maxAsyncSize: optimizationSplitChunksSizes.optional(),
|
||||
maxInitialSize: optimizationSplitChunksSizes.optional(),
|
||||
automaticNameDelimiter: zod_1.z.string().optional()
|
||||
};
|
||||
const optimizationSplitChunksCacheGroup = zod_1.z.strictObject({
|
||||
test: zod_1.z
|
||||
.string()
|
||||
.or(zod_1.z.instanceof(RegExp))
|
||||
.or(zod_1.z
|
||||
.function()
|
||||
.args(zod_1.z.instanceof(Module_1.Module) /** FIXME: lack of CacheGroupContext */))
|
||||
.optional(),
|
||||
priority: zod_1.z.number().optional(),
|
||||
enforce: zod_1.z.boolean().optional(),
|
||||
filename: zod_1.z.string().optional(),
|
||||
reuseExistingChunk: zod_1.z.boolean().optional(),
|
||||
type: zod_1.z.string().or(zod_1.z.instanceof(RegExp)).optional(),
|
||||
idHint: zod_1.z.string().optional(),
|
||||
...sharedOptimizationSplitChunksCacheGroup
|
||||
});
|
||||
const optimizationSplitChunksOptions = zod_1.z.strictObject({
|
||||
cacheGroups: zod_1.z
|
||||
.record(zod_1.z.literal(false).or(optimizationSplitChunksCacheGroup))
|
||||
.optional(),
|
||||
maxAsyncRequests: zod_1.z.number().optional(),
|
||||
maxInitialRequests: zod_1.z.number().optional(),
|
||||
fallbackCacheGroup: zod_1.z
|
||||
.strictObject({
|
||||
chunks: optimizationSplitChunksChunks.optional(),
|
||||
minSize: zod_1.z.number().optional(),
|
||||
maxSize: zod_1.z.number().optional(),
|
||||
maxAsyncSize: zod_1.z.number().optional(),
|
||||
maxInitialSize: zod_1.z.number().optional(),
|
||||
automaticNameDelimiter: zod_1.z.string().optional()
|
||||
})
|
||||
.optional(),
|
||||
hidePathInfo: zod_1.z.boolean().optional(),
|
||||
...sharedOptimizationSplitChunksCacheGroup
|
||||
});
|
||||
const optimization = zod_1.z.strictObject({
|
||||
moduleIds: zod_1.z.enum(["named", "deterministic"]).optional(),
|
||||
chunkIds: zod_1.z.enum(["named", "deterministic"]).optional(),
|
||||
minimize: zod_1.z.boolean().optional(),
|
||||
minimizer: zod_1.z.literal("...").or(plugin).array().optional(),
|
||||
mergeDuplicateChunks: zod_1.z.boolean().optional(),
|
||||
splitChunks: zod_1.z.literal(false).or(optimizationSplitChunksOptions).optional(),
|
||||
runtimeChunk: optimizationRuntimeChunk.optional(),
|
||||
removeAvailableModules: zod_1.z.boolean().optional(),
|
||||
removeEmptyChunks: zod_1.z.boolean().optional(),
|
||||
realContentHash: zod_1.z.boolean().optional(),
|
||||
sideEffects: zod_1.z.enum(["flag"]).or(zod_1.z.boolean()).optional(),
|
||||
providedExports: zod_1.z.boolean().optional(),
|
||||
innerGraph: zod_1.z.boolean().optional(),
|
||||
usedExports: zod_1.z.enum(["global"]).or(zod_1.z.boolean()).optional(),
|
||||
mangleExports: zod_1.z.enum(["size", "deterministic"]).or(zod_1.z.boolean()).optional(),
|
||||
nodeEnv: zod_1.z.union([zod_1.z.string(), zod_1.z.literal(false)]).optional()
|
||||
});
|
||||
//#endregion
|
||||
//#region Experiments
|
||||
const incrementalRebuildOptions = zod_1.z.strictObject({
|
||||
make: zod_1.z.boolean().optional(),
|
||||
emitAsset: zod_1.z.boolean().optional()
|
||||
});
|
||||
const rspackFutureOptions = zod_1.z.strictObject({
|
||||
newResolver: zod_1.z
|
||||
.boolean()
|
||||
.optional()
|
||||
.refine(val => {
|
||||
if (val === false) {
|
||||
(0, util_1.deprecatedWarn)(`'experiments.rspackFuture.newResolver = ${JSON.stringify(val)}' has been deprecated, and will be drop support in 0.5.0, please switch 'experiments.rspackFuture.newResolver = true' to use new resolver, See the discussion ${(0, util_1.termlink)("here", "https://github.com/web-infra-dev/rspack/issues/4825")}`);
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
newTreeshaking: zod_1.z.boolean().optional(),
|
||||
disableTransformByDefault: zod_1.z.boolean().optional()
|
||||
});
|
||||
const experiments = zod_1.z.strictObject({
|
||||
lazyCompilation: zod_1.z.boolean().optional(),
|
||||
incrementalRebuild: zod_1.z
|
||||
.boolean()
|
||||
.or(incrementalRebuildOptions)
|
||||
.optional()
|
||||
.refine(val => {
|
||||
if (val !== undefined) {
|
||||
(0, util_1.deprecatedWarn)(`'experiments.incrementalRebuild' has been deprecated, and will be drop support in 0.5.0. See the discussion ${(0, util_1.termlink)("here", "https://github.com/web-infra-dev/rspack/issues/4708")}`);
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
asyncWebAssembly: zod_1.z.boolean().optional(),
|
||||
outputModule: zod_1.z.boolean().optional(),
|
||||
topLevelAwait: zod_1.z.boolean().optional(),
|
||||
newSplitChunks: zod_1.z
|
||||
.boolean()
|
||||
.optional()
|
||||
.refine(val => {
|
||||
if (val === false) {
|
||||
(0, util_1.deprecatedWarn)(`'experiments.newSplitChunks = ${JSON.stringify(val)}' has been deprecated, please switch to 'experiments.newSplitChunks = true' to use webpack's behavior.
|
||||
See the discussion ${(0, util_1.termlink)("here", "https://github.com/web-infra-dev/rspack/discussions/4168")}`);
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
css: zod_1.z.boolean().optional(),
|
||||
futureDefaults: zod_1.z.boolean().optional(),
|
||||
rspackFuture: rspackFutureOptions.optional()
|
||||
});
|
||||
//#endregion
|
||||
//#region Watch
|
||||
const watch = zod_1.z.boolean();
|
||||
//#endregion
|
||||
//#region WatchOptions
|
||||
const watchOptions = zod_1.z.strictObject({
|
||||
aggregateTimeout: zod_1.z.number().optional(),
|
||||
followSymlinks: zod_1.z.boolean().optional(),
|
||||
ignored: zod_1.z
|
||||
.string()
|
||||
.array()
|
||||
.or(zod_1.z.instanceof(RegExp))
|
||||
.or(zod_1.z.string())
|
||||
.optional(),
|
||||
poll: zod_1.z.number().or(zod_1.z.boolean()).optional(),
|
||||
stdin: zod_1.z.boolean().optional()
|
||||
});
|
||||
const devServer = zod_1.z.custom();
|
||||
//#endregion
|
||||
//#region IgnoreWarnings
|
||||
const ignoreWarnings = zod_1.z
|
||||
.instanceof(RegExp)
|
||||
.or(zod_1.z
|
||||
.function()
|
||||
.args(zod_1.z.instanceof(Error), zod_1.z.custom())
|
||||
.returns(zod_1.z.boolean()))
|
||||
.array();
|
||||
//#endregion
|
||||
//#region Profile
|
||||
const profile = zod_1.z.boolean();
|
||||
//#endregion
|
||||
//#region Builtins (deprecated)
|
||||
const builtins = zod_1.z.custom();
|
||||
const features = zod_1.z.custom();
|
||||
// #endregion
|
||||
exports.rspackOptions = zod_1.z.strictObject({
|
||||
name: name.optional(),
|
||||
dependencies: dependencies.optional(),
|
||||
entry: entry.optional(),
|
||||
output: output.optional(),
|
||||
target: target.optional(),
|
||||
mode: mode.optional(),
|
||||
experiments: experiments.optional(),
|
||||
externals: externals.optional(),
|
||||
externalsType: exports.externalsType.optional(),
|
||||
externalsPresets: externalsPresets.optional(),
|
||||
infrastructureLogging: infrastructureLogging.optional(),
|
||||
cache: cacheOptions.optional(),
|
||||
context: context.optional(),
|
||||
devtool: devTool.optional(),
|
||||
node: node.optional(),
|
||||
ignoreWarnings: ignoreWarnings.optional(),
|
||||
watchOptions: watchOptions.optional(),
|
||||
watch: watch.optional(),
|
||||
stats: statsValue.optional(),
|
||||
snapshot: snapshotOptions.optional(),
|
||||
optimization: optimization.optional(),
|
||||
resolve: resolve.optional(),
|
||||
resolveLoader: resolve.optional(),
|
||||
plugins: plugins.optional(),
|
||||
devServer: devServer.optional(),
|
||||
builtins: builtins.optional(),
|
||||
module: moduleOptions.optional(),
|
||||
profile: profile.optional(),
|
||||
features: features.optional(),
|
||||
});
|
|
@ -231,10 +231,6 @@ const tasks = [
|
|||
// filter out js files and replace with compiled files.
|
||||
const filePaths = globbySync(['**/*'], { cwd: pkgPath, ignore: ['node_modules'] });
|
||||
const filesAddOverwrite = [
|
||||
'dist/config/adapter.js',
|
||||
'dist/config/defaults.js',
|
||||
'dist/config/zod.js',
|
||||
'dist/config/normalization.js',
|
||||
'dist/util/bindingVersionCheck.js',
|
||||
];
|
||||
filePaths.forEach((filePath) => {
|
||||
|
|
|
@ -241,20 +241,24 @@ const userConfig = [
|
|||
{
|
||||
name: 'compileDependencies',
|
||||
validation: 'array|boolean',
|
||||
getDefaultValue: () => (process.env.NODE_ENV === 'development' ? false : [/node_modules\/*/]),
|
||||
setConfig: (config: Config, customValue: UserConfig['compileDependencies']) => {
|
||||
let compileRegex: RegExp | false;
|
||||
getDefaultValue: () => (process.env.NODE_ENV !== 'development'),
|
||||
setConfig: (config: Config, customValue: UserConfig['compileDependencies'], context: UserConfigContext) => {
|
||||
const speedupMode = context.commandArgs.speedup;
|
||||
let compileRegex: RegExp | string | false;
|
||||
if (customValue === true) {
|
||||
compileRegex = /node_modules\/*/;
|
||||
compileRegex = speedupMode ? 'node_modules' : /node_modules\/*/;
|
||||
} else if (customValue && customValue.length > 0) {
|
||||
compileRegex = new RegExp(
|
||||
customValue
|
||||
.map((dep: string | RegExp) => {
|
||||
if (dep instanceof RegExp) {
|
||||
if (speedupMode) {
|
||||
throw new Error('speedup mode does not support config compileDependencies as RegExp');
|
||||
}
|
||||
return dep.source;
|
||||
} else if (typeof dep === 'string') {
|
||||
// add default prefix of node_modules
|
||||
const matchStr = `node_modules/?.+${dep}/`;
|
||||
const matchStr = speedupMode ? dep : `node_modules/?.+${dep}/`;
|
||||
return matchStr;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -30,7 +30,7 @@ export default defineConfig(() => ({
|
|||
### `legacy`
|
||||
|
||||
- Default: `false`
|
||||
- Enable legacy syntax to import Rax like this:
|
||||
- Enable legacy way to import rax as namespace, like `v0.6`:
|
||||
|
||||
```typescript
|
||||
import Rax from 'rax';
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { AliasService } from './services/alias';
|
||||
import { StyleService } from './services/styles';
|
||||
import { JSXService } from './services/jsx';
|
||||
import { TypingsService } from './services/typings';
|
||||
|
||||
import type { Plugin } from '@ice/app/types';
|
||||
import type { NormalizedRaxCompatPluginOptions, RaxCompatPluginOptions } from './typings';
|
||||
|
||||
import { AliasService } from './services/alias.js';
|
||||
import { StyleService } from './services/styles/index.js';
|
||||
import { JSXService } from './services/jsx.js';
|
||||
import { TypingsService } from './services/typings.js';
|
||||
|
||||
const normalizeOptions = (options?: RaxCompatPluginOptions): NormalizedRaxCompatPluginOptions => {
|
||||
const { inlineStyle = false, cssModule = true, legacy = false } = options ?? {};
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import { merge, cloneDeep } from 'lodash-es';
|
|||
import type { NormalizedRaxCompatPluginOptions, PluginAPI } from '../typings';
|
||||
|
||||
export class JSXService {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public static provide(api: PluginAPI, options: NormalizedRaxCompatPluginOptions) {
|
||||
api.onGetConfig((config) => {
|
||||
const originalSwcCompilationConfig =
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { createRequire } from 'module';
|
||||
|
||||
import { checkInlineStyleEnable } from '../../utils';
|
||||
|
||||
import type { RuleSetRule } from 'webpack';
|
||||
import type { NormalizedRaxCompatPluginOptions, PluginAPI, StyleKind, WebpackConfiguration } from '../../typings';
|
||||
|
||||
import { checkInlineStyleEnable } from '../../utils.js';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
const stylesheetLoaderConfig = {
|
||||
|
|
|
@ -2,7 +2,7 @@ import { createRequire } from 'module';
|
|||
|
||||
import { transformSync } from '@babel/core';
|
||||
|
||||
import { checkInlineStyleEnable } from '../../utils';
|
||||
import { checkInlineStyleEnable } from '../../utils.js';
|
||||
|
||||
import type { NormalizedRaxCompatPluginOptions, PluginAPI, Transformer } from '../../typings';
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import fs from 'fs';
|
||||
|
||||
import styleSheetLoader from '../../lib/transform-styles';
|
||||
import styleSheetLoader from '../../lib/transform-styles.js';
|
||||
|
||||
import { checkInlineStyleEnable, checkStyleKind } from '../../utils';
|
||||
import { checkInlineStyleEnable, checkStyleKind } from '../../utils.js';
|
||||
|
||||
import type { ESBuildPlugin, NormalizedRaxCompatPluginOptions, PluginAPI } from '../../typings';
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import chalk from 'chalk';
|
||||
import { applyClientSideStyleProcessor } from './applyClientSideProcessor';
|
||||
import { applyJSXClassNameTransformer } from './applyJSXClassNameTransormer';
|
||||
import { applyServerSideStyleProcessor } from './applyServerSideProcessor';
|
||||
|
||||
import type { NormalizedRaxCompatPluginOptions, PluginAPI } from '../../typings';
|
||||
|
||||
import { applyClientSideStyleProcessor } from './applyClientSideProcessor.js';
|
||||
import { applyJSXClassNameTransformer } from './applyJSXClassNameTransormer.js';
|
||||
import { applyServerSideStyleProcessor } from './applyServerSideProcessor.js';
|
||||
|
||||
/**
|
||||
* Handle inline style related.
|
||||
*/
|
||||
|
|
|
@ -3,9 +3,10 @@ import { fileURLToPath } from 'url';
|
|||
|
||||
import type { NormalizedRaxCompatPluginOptions, PluginAPI } from '../typings';
|
||||
|
||||
const dirname = __dirname ?? path.dirname(fileURLToPath(import.meta.url));
|
||||
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
export class TypingsService {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public static provide(api: PluginAPI, options: NormalizedRaxCompatPluginOptions) {
|
||||
api.generator.addRenderFile(path.join(dirname, '../templates/rax-compat.d.ts'), 'rax-compat.d.ts', {});
|
||||
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
import * as rax from 'rax-compat';
|
||||
|
||||
// For namespace / named import usage(v1.0)
|
||||
export * from 'rax-compat';
|
||||
|
||||
// For legacy default import usage(v0.6+) like: import Rax from 'rax'
|
||||
export default { ...rax }
|
||||
|
||||
const typeChecker = () => {};
|
||||
|
||||
export const PropTypes = {
|
||||
|
|
|
@ -43,4 +43,4 @@ export interface RaxCompatPluginOptions {
|
|||
legacy?: boolean;
|
||||
}
|
||||
|
||||
export interface NormalizedRaxCompatPluginOptions extends Required<RaxCompatPluginOptions> {}
|
||||
export type NormalizedRaxCompatPluginOptions = Required<RaxCompatPluginOptions>;
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
import type {
|
||||
Attributes,
|
||||
FunctionComponent,
|
||||
ReactElement,
|
||||
ReactNode,
|
||||
} from 'react';
|
||||
import type { Attributes, CSSProperties, FunctionComponent, HTMLAttributes, ReactElement, ReactNode } from 'react';
|
||||
import { createElement as _createElement } from 'react';
|
||||
import { createJSXElementFactory } from './compat/element.js';
|
||||
|
||||
const jsx = createJSXElementFactory((type: any, props: any, ...children: ReactNode[]) =>
|
||||
_createElement(type, props, ...children));
|
||||
_createElement(type, props, ...children),
|
||||
);
|
||||
|
||||
/**
|
||||
* Transform array type style to avoid
|
||||
* `Failed to set an indexed property on 'CSSStyleDeclaration': Index property setter is not supported`
|
||||
* error.
|
||||
*/
|
||||
const normalizeStyleProp = (style: (CSSProperties | CSSProperties[])[]) => {
|
||||
return style.flat().reduce((acc, val) => {
|
||||
return { ...acc, ...val };
|
||||
}, {});
|
||||
};
|
||||
|
||||
/**
|
||||
* Compat createElement for rax export.
|
||||
|
@ -20,7 +27,21 @@ const jsx = createJSXElementFactory((type: any, props: any, ...children: ReactNo
|
|||
*/
|
||||
export function createElement<P>(
|
||||
type: FunctionComponent<P> | string,
|
||||
props?: Attributes & P | null,
|
||||
...children: ReactNode[]): ReactElement {
|
||||
return jsx(type, props, ...children);
|
||||
props?: (Attributes & P & HTMLAttributes<any>) | null,
|
||||
...children: ReactNode[]
|
||||
): ReactElement {
|
||||
if (Array.isArray(props?.style)) {
|
||||
const normalizedStyle = normalizeStyleProp(props.style);
|
||||
|
||||
return jsx(
|
||||
type,
|
||||
{
|
||||
...props,
|
||||
style: normalizedStyle,
|
||||
},
|
||||
...children,
|
||||
);
|
||||
}
|
||||
|
||||
return jsx(type, props as object, ...children);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as path from 'path';
|
||||
import { createRequire } from 'module';
|
||||
import { compilationPlugin, compileExcludes, getDefineVars, getCompilerPlugins, getJsxTransformOptions, getAliasWithRoot } from '@ice/shared-config';
|
||||
import { getDefineVars, getCompilerPlugins, getJsxTransformOptions, getAliasWithRoot, skipCompilePackages } from '@ice/shared-config';
|
||||
import type { Config, ModifyWebpackConfig } from '@ice/shared-config/types';
|
||||
import type { Configuration, rspack as Rspack } from '@rspack/core';
|
||||
import lodash from '@ice/bundles/compiled/lodash/index.js';
|
||||
|
@ -52,9 +52,7 @@ const getConfig: GetConfig = async (options) => {
|
|||
mode,
|
||||
minify,
|
||||
publicPath = '/',
|
||||
cacheDir,
|
||||
outputDir = 'build',
|
||||
sourceMap,
|
||||
externals = {},
|
||||
alias = {},
|
||||
compileIncludes,
|
||||
|
@ -75,19 +73,6 @@ const getConfig: GetConfig = async (options) => {
|
|||
const isDev = mode === 'development';
|
||||
const absoluteOutputDir = path.isAbsolute(outputDir) ? outputDir : path.join(rootDir, outputDir);
|
||||
const hashKey = hash === true ? 'hash:8' : (hash || '');
|
||||
const compilation = compilationPlugin({
|
||||
rootDir,
|
||||
cacheDir,
|
||||
sourceMap,
|
||||
fastRefresh: false,
|
||||
mode,
|
||||
compileIncludes,
|
||||
compileExcludes,
|
||||
swcOptions,
|
||||
polyfill,
|
||||
enableEnv: true,
|
||||
getRoutesFile,
|
||||
});
|
||||
|
||||
const { rspack: { DefinePlugin, ProvidePlugin, SwcJsMinimizerRspackPlugin } } = await import('@ice/bundles/esm/rspack.js');
|
||||
const cssFilename = `css/${hashKey ? `[name]-[${hashKey}].css` : '[name].css'}`;
|
||||
|
@ -128,6 +113,19 @@ const getConfig: GetConfig = async (options) => {
|
|||
? splitChunks
|
||||
: getSplitChunks(rootDir, splitChunks);
|
||||
}
|
||||
// Get built-in exclude packages.
|
||||
const compileExclude = skipCompilePackages.map((pkg) => {
|
||||
return `node_modules[\\/](${pkg}[\\/]|_${pkg.replace('/', '_')}@[^/]+[\\/])`;
|
||||
});
|
||||
let excludeRule: string;
|
||||
|
||||
if (!compileIncludes || compileIncludes?.length === 0) {
|
||||
excludeRule = 'node_modules';
|
||||
} else if (!compileIncludes?.includes('node_modules') && compileIncludes?.length > 0) {
|
||||
excludeRule = `node_modules[\\/](?!${compileIncludes.map((pkg: string) => {
|
||||
return `${pkg}[\\/]|_${pkg.replace('/', '_')}@[^/]+[\\/]`;
|
||||
}).join('|')}).*`;
|
||||
}
|
||||
const config: Configuration = {
|
||||
entry: {
|
||||
main: [path.join(rootDir, runtimeTmpDir, 'entry.client.tsx')],
|
||||
|
@ -148,8 +146,8 @@ const getConfig: GetConfig = async (options) => {
|
|||
module: {
|
||||
rules: [
|
||||
{
|
||||
// TODO: use regexp to improve performance.
|
||||
test: compilation.transformInclude,
|
||||
test: /\.(jsx?|tsx?|mjs)$/,
|
||||
...(excludeRule ? { exclude: new RegExp(excludeRule) } : {}),
|
||||
use: {
|
||||
loader: 'builtin:compilation-loader',
|
||||
options: {
|
||||
|
@ -158,6 +156,10 @@ const getConfig: GetConfig = async (options) => {
|
|||
removeExport: swcOptions.removeExportExprs,
|
||||
keepExport: swcOptions.keepExports,
|
||||
},
|
||||
compileRules: {
|
||||
// "bundles/compiled" is the path when using @ice/bundles.
|
||||
exclude: [...compileExclude, 'bundles/compiled'],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
diff --git a/dist/config/adapter.js b/dist/config/adapter.js
|
||||
index 40175429036fbeac26601c59e19c3d2ec1bebd14..5e378ec28ffe510bcffbf4c0c8a64fbf1b545c4c 100644
|
||||
--- a/dist/config/adapter.js
|
||||
+++ b/dist/config/adapter.js
|
||||
@@ -17,6 +17,8 @@ const getRawOptions = (options, compiler, processResource) => {
|
||||
const mode = options.mode;
|
||||
const experiments = getRawExperiments(options.experiments);
|
||||
return {
|
||||
+ // CUSTOM: add options of features.
|
||||
+ features: options.features,
|
||||
mode,
|
||||
target: getRawTarget(options.target),
|
||||
context: options.context,
|
||||
diff --git a/dist/config/defaults.js b/dist/config/defaults.js
|
||||
index 48239ccd62799ac615d095f0df1fe20f316c6052..68db4c167b989f2fbba0e34e8d2a876c0fc2f4c5 100644
|
||||
--- a/dist/config/defaults.js
|
||||
+++ b/dist/config/defaults.js
|
||||
@@ -50,6 +50,12 @@ const applyRspackOptionsDefaults = (options) => {
|
||||
applyExperimentsDefaults(options.experiments, {
|
||||
cache: options.cache
|
||||
});
|
||||
+ // CUSTOM: add default rules for features options.
|
||||
+ if (options.features) {
|
||||
+ applyFeaturesDefaults(options.features);
|
||||
+ } else {
|
||||
+ D(options, 'features', {});
|
||||
+ }
|
||||
applySnapshotDefaults(options.snapshot, { production });
|
||||
applyModuleDefaults(options.module, {
|
||||
// syncWebAssembly: options.experiments.syncWebAssembly,
|
||||
@@ -125,6 +131,13 @@ const applyExperimentsDefaults = (experiments, { cache }) => {
|
||||
D(experiments.rspackFuture, "disableTransformByDefault", true);
|
||||
}
|
||||
};
|
||||
+const applyFeaturesDefaults = (features) => {
|
||||
+ D(features, 'split_chunks_strategy', {});
|
||||
+ if (typeof features.split_chunks_strategy === 'object') {
|
||||
+ D(features.split_chunks_strategy, 'name', '');
|
||||
+ D(features.split_chunks_strategy, 'topLevelFrameworks', []);
|
||||
+ }
|
||||
+};
|
||||
const applySnapshotDefaults = (snapshot, { production }) => {
|
||||
F(snapshot, "module", () => production
|
||||
? { timestamp: true, hash: true }
|
||||
diff --git a/dist/config/normalization.js b/dist/config/normalization.js
|
||||
index 1d7a4499463026c6b8bd528159c2d5edf300942c..942bfc868423c07d239a1225cf6063ecbcacc694 100644
|
||||
--- a/dist/config/normalization.js
|
||||
+++ b/dist/config/normalization.js
|
||||
@@ -13,6 +13,7 @@ exports.getNormalizedRspackOptions = void 0;
|
||||
const util_1 = require("../util");
|
||||
const getNormalizedRspackOptions = (config) => {
|
||||
return {
|
||||
+ features: config.features,
|
||||
ignoreWarnings: config.ignoreWarnings !== undefined
|
||||
? config.ignoreWarnings.map(ignore => {
|
||||
if (typeof ignore === "function") {
|
||||
diff --git a/dist/config/zod.js b/dist/config/zod.js
|
||||
index 028aa93bf7b0b813b3b1b1bab62a3c5176855896..0364b4c91973b1b5a3dee2c64475c022aed969d7 100644
|
||||
--- a/dist/config/zod.js
|
||||
+++ b/dist/config/zod.js
|
||||
@@ -703,7 +703,8 @@ const profile = zod_1.z.boolean();
|
||||
//#endregion
|
||||
//#region Builtins (deprecated)
|
||||
const builtins = zod_1.z.custom();
|
||||
-//#endregion
|
||||
+const features = zod_1.z.custom();
|
||||
+// #endregion
|
||||
exports.rspackOptions = zod_1.z.strictObject({
|
||||
name: name.optional(),
|
||||
dependencies: dependencies.optional(),
|
||||
@@ -732,5 +733,6 @@ exports.rspackOptions = zod_1.z.strictObject({
|
||||
devServer: devServer.optional(),
|
||||
builtins: builtins.optional(),
|
||||
module: moduleOptions.optional(),
|
||||
- profile: profile.optional()
|
||||
+ profile: profile.optional(),
|
||||
+ features: features.optional(),
|
||||
});
|
|
@ -5,6 +5,9 @@ settings:
|
|||
excludeLinksFromLockfile: false
|
||||
|
||||
patchedDependencies:
|
||||
'@rspack/core@0.4.3':
|
||||
hash: gsshcxtimrefunsmcelqkw7oa4
|
||||
path: patches/@rspack__core@0.4.3.patch
|
||||
unplugin@1.5.1:
|
||||
hash: eanypstkeladyqkfllfbryx6lu
|
||||
path: patches/unplugin@1.5.1.patch
|
||||
|
@ -1371,7 +1374,7 @@ importers:
|
|||
version: 0.5.10(react-refresh@0.14.0)(webpack-dev-server@4.15.0)(webpack@5.88.2)
|
||||
'@rspack/core':
|
||||
specifier: 0.4.3
|
||||
version: 0.4.3
|
||||
version: 0.4.3(patch_hash=gsshcxtimrefunsmcelqkw7oa4)
|
||||
'@rspack/dev-server':
|
||||
specifier: 0.4.3
|
||||
version: 0.4.3(@rspack/core@0.4.3)(@swc/core@1.3.80)(esbuild@0.17.16)(react-refresh@0.14.0)
|
||||
|
@ -1698,7 +1701,7 @@ importers:
|
|||
devDependencies:
|
||||
'@rspack/core':
|
||||
specifier: 0.4.3
|
||||
version: 0.4.3
|
||||
version: 0.4.3(patch_hash=gsshcxtimrefunsmcelqkw7oa4)
|
||||
'@rspack/dev-server':
|
||||
specifier: 0.4.3
|
||||
version: 0.4.3(@rspack/core@0.4.3)(@types/express@4.17.17)(esbuild@0.17.16)
|
||||
|
@ -2299,7 +2302,7 @@ importers:
|
|||
devDependencies:
|
||||
'@rspack/core':
|
||||
specifier: 0.4.3
|
||||
version: 0.4.3
|
||||
version: 0.4.3(patch_hash=gsshcxtimrefunsmcelqkw7oa4)
|
||||
|
||||
packages/runtime:
|
||||
dependencies:
|
||||
|
@ -8011,7 +8014,7 @@ packages:
|
|||
'@rspack/binding-win32-x64-msvc': 0.4.3
|
||||
dev: true
|
||||
|
||||
/@rspack/core@0.4.3:
|
||||
/@rspack/core@0.4.3(patch_hash=gsshcxtimrefunsmcelqkw7oa4):
|
||||
resolution: {integrity: sha512-YKzOOt6v6vZZH15+HdwWbd7DdXdXIJLlYQdQ6jgrAK7/X+5qg99MUgsfra3k+MXXX0vWROOy8mM6/dBaaDb7tg==}
|
||||
engines: {node: '>=16.0.0'}
|
||||
dependencies:
|
||||
|
@ -8032,13 +8035,14 @@ packages:
|
|||
zod: 3.22.3
|
||||
zod-validation-error: 1.3.1(zod@3.22.3)
|
||||
dev: true
|
||||
patched: true
|
||||
|
||||
/@rspack/dev-server@0.4.3(@rspack/core@0.4.3)(@swc/core@1.3.80)(esbuild@0.17.16)(react-refresh@0.14.0):
|
||||
resolution: {integrity: sha512-qbggWEySoWdCrbWxqV+HX7nXgyT6qE3DqGtdYKzX9RLPp+RilXtnPlXtwY1AXNh8e0gYe1dMpvTcHYxeSglZSg==}
|
||||
peerDependencies:
|
||||
'@rspack/core': '*'
|
||||
dependencies:
|
||||
'@rspack/core': 0.4.3
|
||||
'@rspack/core': 0.4.3(patch_hash=gsshcxtimrefunsmcelqkw7oa4)
|
||||
'@rspack/plugin-react-refresh': 0.4.3(react-refresh@0.14.0)
|
||||
chokidar: 3.5.3
|
||||
connect-history-api-fallback: 2.0.0
|
||||
|
@ -8067,7 +8071,7 @@ packages:
|
|||
peerDependencies:
|
||||
'@rspack/core': '*'
|
||||
dependencies:
|
||||
'@rspack/core': 0.4.3
|
||||
'@rspack/core': 0.4.3(patch_hash=gsshcxtimrefunsmcelqkw7oa4)
|
||||
'@rspack/plugin-react-refresh': 0.4.3(react-refresh@0.14.0)
|
||||
chokidar: 3.5.3
|
||||
connect-history-api-fallback: 2.0.0
|
||||
|
|
Loading…
Reference in New Issue