diff --git a/packages/core/src/configChain.ts b/packages/core/src/configChain.ts index b285fe6a00..4fa5008933 100644 --- a/packages/core/src/configChain.ts +++ b/packages/core/src/configChain.ts @@ -85,6 +85,8 @@ export const CHAIN_ID = { }, /** Predefined rule groups */ ONE_OF: { + JS_TRANSFORM: 'js-transform', + JS_RAW: 'js-raw', SVG: 'svg', SVG_RAW: 'svg-asset-raw', SVG_URL: 'svg-asset-url', diff --git a/packages/core/src/plugins/swc.ts b/packages/core/src/plugins/swc.ts index 5f0b47bbe3..f907c28423 100644 --- a/packages/core/src/plugins/swc.ts +++ b/packages/core/src/plugins/swc.ts @@ -121,19 +121,20 @@ export const pluginSwc = (): RsbuildPlugin => ({ const rule = chain.module .rule(CHAIN_ID.RULE.JS) .test(SCRIPT_REGEX) - .type('javascript/auto') // When using `new URL('./path/to/foo.js', import.meta.url)`, // the module should be treated as an asset module rather than a JS module. - .dependency({ not: 'url' }) - // exclude `import './foo.js?raw'` - .resourceQuery({ not: RAW_QUERY_REGEX }); + .dependency({ not: 'url' }); // Support for `import rawJs from "a.js?raw"` - chain.module - .rule(CHAIN_ID.RULE.JS_RAW) - .test(SCRIPT_REGEX) - .type('asset/source') - .resourceQuery(RAW_QUERY_REGEX); + rule + .oneOf(CHAIN_ID.ONE_OF.JS_RAW) + .resourceQuery(RAW_QUERY_REGEX) + .type('asset/source'); + + // Transform TypeScript/JSX/ESNext code + const transformRule = rule + .oneOf(CHAIN_ID.ONE_OF.JS_TRANSFORM) + .type('javascript/auto'); const dataUriRule = chain.module .rule(CHAIN_ID.RULE.JS_DATA_URI) @@ -171,7 +172,7 @@ export const pluginSwc = (): RsbuildPlugin => ({ api.context.rootPath, ); if (coreJsDir) { - for (const item of [rule, dataUriRule]) { + for (const item of [transformRule, dataUriRule]) { item.resolve.alias.set('core-js', coreJsDir); } } @@ -194,7 +195,7 @@ export const pluginSwc = (): RsbuildPlugin => ({ delete mergedConfig.env; } - rule + transformRule .use(CHAIN_ID.USE.SWC) .loader(builtinSwcLoaderName) .options(mergedConfig); diff --git a/packages/core/tests/__snapshots__/builder.test.ts.snap b/packages/core/tests/__snapshots__/builder.test.ts.snap index c2e090d974..62214fc88d 100644 --- a/packages/core/tests/__snapshots__/builder.test.ts.snap +++ b/packages/core/tests/__snapshots__/builder.test.ts.snap @@ -130,55 +130,55 @@ exports[`should use Rspack as the default bundler > apply Rspack correctly 1`] = /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, /\\[\\\\\\\\/\\]@rsbuild\\[\\\\\\\\/\\]core\\[\\\\\\\\/\\]dist\\[\\\\\\\\/\\]/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { diff --git a/packages/core/tests/__snapshots__/default.test.ts.snap b/packages/core/tests/__snapshots__/default.test.ts.snap index b3a7f013cd..f311d28d4e 100644 --- a/packages/core/tests/__snapshots__/default.test.ts.snap +++ b/packages/core/tests/__snapshots__/default.test.ts.snap @@ -130,55 +130,55 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, /\\[\\\\\\\\/\\]@rsbuild\\[\\\\\\\\/\\]core\\[\\\\\\\\/\\]dist\\[\\\\\\\\/\\]/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -641,55 +641,55 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": true, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": true, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -1158,52 +1158,52 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "node >= 20", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "node >= 20", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -1628,55 +1628,55 @@ exports[`tools.rspack > should match snapshot 1`] = ` /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, /\\[\\\\\\\\/\\]@rsbuild\\[\\\\\\\\/\\]core\\[\\\\\\\\/\\]dist\\[\\\\\\\\/\\]/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { diff --git a/packages/core/tests/__snapshots__/environments.test.ts.snap b/packages/core/tests/__snapshots__/environments.test.ts.snap index 263ac2117a..f642a5db03 100644 --- a/packages/core/tests/__snapshots__/environments.test.ts.snap +++ b/packages/core/tests/__snapshots__/environments.test.ts.snap @@ -1579,55 +1579,55 @@ exports[`environment config > tools.rspack / bundlerChain can be configured in e /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, /\\[\\\\\\\\/\\]@rsbuild\\[\\\\\\\\/\\]core\\[\\\\\\\\/\\]dist\\[\\\\\\\\/\\]/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -2014,52 +2014,52 @@ exports[`environment config > tools.rspack / bundlerChain can be configured in e }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "node >= 20", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "node >= 20", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { diff --git a/packages/core/tests/__snapshots__/swc.test.ts.snap b/packages/core/tests/__snapshots__/swc.test.ts.snap index 0a7fa7f4e2..efafa2a395 100644 --- a/packages/core/tests/__snapshots__/swc.test.ts.snap +++ b/packages/core/tests/__snapshots__/swc.test.ts.snap @@ -20,52 +20,52 @@ exports[`plugin-swc > should add browserslist 1`] = ` }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome 98", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome 98", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -145,62 +145,62 @@ exports[`plugin-swc > should add pluginImport 1`] = ` }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, - }, - }, - "rspackExperiments": { - "import": [ - { - "libraryName": "foo", + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, }, - ], + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, + "rspackExperiments": { + "import": [ + { + "libraryName": "foo", + }, + ], + }, + }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -282,26 +282,26 @@ exports[`plugin-swc > should allow to use \`tools.swc\` to be function type 1`] }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "jsc": { - "externalHelpers": false, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "jsc": { + "externalHelpers": false, + }, + }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -339,55 +339,55 @@ exports[`plugin-swc > should allow to use \`tools.swc\` to configure swc-loader }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": false, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": false, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -457,70 +457,70 @@ exports[`plugin-swc > should apply environment config correctly 1`] = ` }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resolve": { - "alias": { - "core-js": "/node_modules//core-js", + "oneOf": [ + { + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", }, - }, - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "coreJs": "3.47", - "mode": "usage", - "shippedProposals": true, - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], + "resolve": { + "alias": { + "core-js": "/node_modules//core-js", }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, - }, - }, - "rspackExperiments": { - "import": [ - { - "libraryName": "foo", + }, + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, }, - ], + "env": { + "coreJs": "3.47", + "mode": "usage", + "shippedProposals": true, + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, + "rspackExperiments": { + "import": [ + { + "libraryName": "foo", + }, + ], + }, + }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -603,59 +603,59 @@ exports[`plugin-swc > should apply environment config correctly 2`] = ` }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "node >= 20", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, - }, - }, - "rspackExperiments": { - "import": [ - { - "libraryName": "bar", + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, }, - ], + "env": { + "targets": [ + "node >= 20", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, + "rspackExperiments": { + "import": [ + { + "libraryName": "bar", + }, + ], + }, + }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -734,65 +734,65 @@ exports[`plugin-swc > should apply pluginImport correctly when ConfigChain 1`] = }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, - }, - }, - "rspackExperiments": { - "import": [ - { - "libraryName": "foo", + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, }, - { - "libraryName": "bar", + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], }, - ], + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, + "rspackExperiments": { + "import": [ + { + "libraryName": "foo", + }, + { + "libraryName": "bar", + }, + ], + }, + }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -885,183 +885,55 @@ exports[`plugin-swc > should disable pluginImport when return undefined 1`] = ` }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ - { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, - }, - }, - }, - }, - ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", - }, - { - "mimetype": { - "or": [ - "text/javascript", - "application/javascript", - ], - }, - "resolve": { - "fullySpecified": false, - }, - "use": [ - { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, - }, - }, - }, - }, - ], - }, - ], - }, - "plugins": [ - { - "name": "RsbuildCorePlugin", - }, - ], - }, -] -`; - -exports[`plugin-swc > should disable preset_env in target other than web 1`] = ` -[ - { - "entry": { - "main": [ - "./src/index.js", - ], - }, - "module": { - "rules": [ - { - "dependency": { - "not": "url", - }, - "include": [ + "oneOf": [ { - "not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", }, - /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, - ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "node >= 20", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -1083,7 +955,10 @@ exports[`plugin-swc > should disable preset_env in target other than web 1`] = ` }, "env": { "targets": [ - "node >= 20", + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", ], }, "isModule": "unknown", @@ -1121,7 +996,7 @@ exports[`plugin-swc > should disable preset_env in target other than web 1`] = ` ] `; -exports[`plugin-swc > should disable preset_env mode 1`] = ` +exports[`plugin-swc > should disable preset_env in target other than web 1`] = ` [ { "entry": { @@ -1141,11 +1016,63 @@ exports[`plugin-swc > should disable preset_env mode 1`] = ` }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, + "oneOf": [ + { + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "node >= 20", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, + }, + }, + ], + }, + ], "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", + }, + { + "mimetype": { + "or": [ + "text/javascript", + "application/javascript", + ], + }, + "resolve": { + "fullySpecified": false, + }, "use": [ { "loader": "builtin:swc-loader", @@ -1156,10 +1083,7 @@ exports[`plugin-swc > should disable preset_env mode 1`] = ` }, "env": { "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", + "node >= 20", ], }, "isModule": "unknown", @@ -1186,10 +1110,86 @@ exports[`plugin-swc > should disable preset_env mode 1`] = ` }, ], }, + ], + }, + "plugins": [ + { + "name": "RsbuildCorePlugin", + }, + ], + }, +] +`; + +exports[`plugin-swc > should disable preset_env mode 1`] = ` +[ + { + "entry": { + "main": [ + "./src/index.js", + ], + }, + "module": { + "rules": [ { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "dependency": { + "not": "url", + }, + "include": [ + { + "not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/, + }, + /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, + ], + "oneOf": [ + { + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, + }, + }, + ], + }, + ], "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -1273,62 +1273,62 @@ exports[`plugin-swc > should enable entry mode preset_env 1`] = ` }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resolve": { - "alias": { - "core-js": "/node_modules//core-js", + "oneOf": [ + { + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", }, - }, - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "coreJs": "3.47", - "mode": "entry", - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], + "resolve": { + "alias": { + "core-js": "/node_modules//core-js", }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, + }, + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "coreJs": "3.47", + "mode": "entry", + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -1416,63 +1416,63 @@ exports[`plugin-swc > should enable usage mode preset_env 1`] = ` }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resolve": { - "alias": { - "core-js": "/node_modules//core-js", + "oneOf": [ + { + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", }, - }, - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "coreJs": "3.47", - "mode": "usage", - "shippedProposals": true, - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], + "resolve": { + "alias": { + "core-js": "/node_modules//core-js", }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, + }, + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "coreJs": "3.47", + "mode": "usage", + "shippedProposals": true, + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -1562,62 +1562,62 @@ exports[`plugin-swc > should has correct core-js 1`] = ` }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resolve": { - "alias": { - "core-js": "/node_modules//core-js", + "oneOf": [ + { + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", }, - }, - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "coreJs": "3.47", - "mode": "entry", - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], + "resolve": { + "alias": { + "core-js": "/node_modules//core-js", }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, + }, + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "coreJs": "3.47", + "mode": "entry", + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { @@ -1705,52 +1705,52 @@ exports[`plugin-swc > should has correct core-js 2`] = ` }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "node >= 20", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "node >= 20", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/core/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "mimetype": { diff --git a/packages/plugin-babel/src/helper.ts b/packages/plugin-babel/src/helper.ts index c431facce2..be94859d5d 100644 --- a/packages/plugin-babel/src/helper.ts +++ b/packages/plugin-babel/src/helper.ts @@ -189,14 +189,17 @@ export const modifyBabelLoaderOptions = ({ CHAIN_ID: ChainIdentifier; modifier: (config: BabelTransformOptions) => BabelTransformOptions; }): void => { - const ruleIds = [CHAIN_ID.RULE.JS, CHAIN_ID.RULE.JS_DATA_URI, BABEL_JS_RULE]; - - for (const ruleId of ruleIds) { - if (chain.module.rules.has(ruleId)) { - const rule = chain.module.rule(ruleId); - if (rule.uses.has(CHAIN_ID.USE.BABEL)) { - rule.use(CHAIN_ID.USE.BABEL).tap(modifier); - } + const rules = [ + chain.module.rules + .get(CHAIN_ID.RULE.JS) + .oneOfs.get(CHAIN_ID.ONE_OF.JS_TRANSFORM), + chain.module.rules.get(CHAIN_ID.RULE.JS_DATA_URI), + chain.module.rules.get(BABEL_JS_RULE), + ].filter(Boolean); + + for (const rule of rules) { + if (rule.uses.has(CHAIN_ID.USE.BABEL)) { + rule.use(CHAIN_ID.USE.BABEL).tap(modifier); } } }; diff --git a/packages/plugin-babel/src/plugin.ts b/packages/plugin-babel/src/plugin.ts index cd6f4b7be5..c309a400f9 100644 --- a/packages/plugin-babel/src/plugin.ts +++ b/packages/plugin-babel/src/plugin.ts @@ -140,7 +140,7 @@ export const pluginBabel = ( if (include || exclude) { const rule = chain.module .rule(BABEL_JS_RULE) - // run babel loader before the builtin SWC loader + // run babel loader before the builtin JS rule // https://stackoverflow.com/questions/32234329/what-is-the-loader-order-for-webpack .after(CHAIN_ID.RULE.JS); @@ -162,9 +162,11 @@ export const pluginBabel = ( .options(babelOptions); } else { // already set source.include / exclude in plugin-swc - const rule = chain.module.rule(CHAIN_ID.RULE.JS); - rule - .test(SCRIPT_REGEX) + const jsRule = chain.module.rule(CHAIN_ID.RULE.JS).test(SCRIPT_REGEX); + const jsTransformRule = jsRule.oneOfs.get( + CHAIN_ID.ONE_OF.JS_TRANSFORM, + ); + jsTransformRule .use(CHAIN_ID.USE.BABEL) .after(CHAIN_ID.USE.SWC) .loader(babelLoader) diff --git a/packages/plugin-babel/tests/__snapshots__/index.test.ts.snap b/packages/plugin-babel/tests/__snapshots__/index.test.ts.snap index 91a0902e6d..127c6aed99 100644 --- a/packages/plugin-babel/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-babel/tests/__snapshots__/index.test.ts.snap @@ -15,78 +15,83 @@ exports[`plugins/babel > babel-loader should works with builtin:swc-loader 1`] = /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, /node_modules\\[\\\\\\\\/\\]query-string\\[\\\\\\\\/\\]/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/plugin-babel/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, - }, - }, - }, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", }, { - "loader": "/packages/plugin-babel/compiled/babel-loader/index.js", - "options": { - "babelrc": false, - "compact": false, - "configFile": false, - "plugins": [ - [ - "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", - { - "version": "2022-03", + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], }, - ], - ], - "presets": [ - [ - "/node_modules//@babel/preset-typescript/lib/index.js", - { - "allExtensions": true, - "allowDeclareFields": true, - "allowNamespaces": true, - "isTSX": true, - "optimizeConstEnums": true, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/plugin-babel/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, }, - ], - ], - }, + }, + }, + { + "loader": "/packages/plugin-babel/compiled/babel-loader/index.js", + "options": { + "babelrc": false, + "compact": false, + "configFile": false, + "plugins": [ + [ + "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", + { + "version": "2022-03", + }, + ], + ], + "presets": [ + [ + "/node_modules//@babel/preset-typescript/lib/index.js", + { + "allExtensions": true, + "allowDeclareFields": true, + "allowNamespaces": true, + "isTSX": true, + "optimizeConstEnums": true, + }, + ], + ], + }, + }, + ], }, ], + "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, } `; @@ -104,78 +109,83 @@ exports[`plugins/babel > should apply environment config correctly 1`] = ` }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/plugin-babel/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, - }, - }, - }, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", }, { - "loader": "/packages/plugin-babel/compiled/babel-loader/index.js", - "options": { - "babelrc": false, - "compact": false, - "configFile": false, - "plugins": [ - [ - "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", - { - "version": "2022-03", + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, }, - ], - ], - "presets": [ - [ - "/node_modules//@babel/preset-typescript/lib/index.js", - { - "allExtensions": true, - "allowDeclareFields": true, - "allowNamespaces": true, - "isTSX": true, - "optimizeConstEnums": true, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], }, - ], - ], - }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/plugin-babel/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, + }, + }, + { + "loader": "/packages/plugin-babel/compiled/babel-loader/index.js", + "options": { + "babelrc": false, + "compact": false, + "configFile": false, + "plugins": [ + [ + "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", + { + "version": "2022-03", + }, + ], + ], + "presets": [ + [ + "/node_modules//@babel/preset-typescript/lib/index.js", + { + "allExtensions": true, + "allowDeclareFields": true, + "allowNamespaces": true, + "isTSX": true, + "optimizeConstEnums": true, + }, + ], + ], + }, + }, + ], }, ], + "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, } `; @@ -193,77 +203,82 @@ exports[`plugins/babel > should apply environment config correctly 2`] = ` }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "node >= 20", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/plugin-babel/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorMetadata": true, - "legacyDecorator": true, - "useDefineForClassFields": false, - }, - }, - }, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", }, { - "loader": "/packages/plugin-babel/compiled/babel-loader/index.js", - "options": { - "babelrc": false, - "compact": false, - "configFile": false, - "plugins": [ - [ - "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", - { - "version": "legacy", + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "node >= 20", + ], }, - ], - "/node_modules//@babel/plugin-transform-class-properties/lib/index.js", - ], - "presets": [ - [ - "/node_modules//@babel/preset-typescript/lib/index.js", - { - "allExtensions": true, - "allowDeclareFields": true, - "allowNamespaces": true, - "isTSX": true, - "optimizeConstEnums": true, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/plugin-babel/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorMetadata": true, + "legacyDecorator": true, + "useDefineForClassFields": false, + }, }, - ], - ], - }, + }, + }, + { + "loader": "/packages/plugin-babel/compiled/babel-loader/index.js", + "options": { + "babelrc": false, + "compact": false, + "configFile": false, + "plugins": [ + [ + "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", + { + "version": "legacy", + }, + ], + "/node_modules//@babel/plugin-transform-class-properties/lib/index.js", + ], + "presets": [ + [ + "/node_modules//@babel/preset-typescript/lib/index.js", + { + "allExtensions": true, + "allowDeclareFields": true, + "allowNamespaces": true, + "isTSX": true, + "optimizeConstEnums": true, + }, + ], + ], + }, + }, + ], }, ], + "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, } `; @@ -278,78 +293,83 @@ exports[`plugins/babel > should set babel-loader 1`] = ` }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/plugin-babel/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, - }, - }, - }, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", }, { - "loader": "/packages/plugin-babel/compiled/babel-loader/index.js", - "options": { - "babelrc": false, - "compact": false, - "configFile": false, - "plugins": [ - [ - "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", - { - "version": "2022-03", + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, }, - ], - ], - "presets": [ - [ - "/node_modules//@babel/preset-typescript/lib/index.js", - { - "allExtensions": true, - "allowDeclareFields": true, - "allowNamespaces": true, - "isTSX": true, - "optimizeConstEnums": true, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], }, - ], - ], - }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/plugin-babel/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, + }, + }, + { + "loader": "/packages/plugin-babel/compiled/babel-loader/index.js", + "options": { + "babelrc": false, + "compact": false, + "configFile": false, + "plugins": [ + [ + "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", + { + "version": "2022-03", + }, + ], + ], + "presets": [ + [ + "/node_modules//@babel/preset-typescript/lib/index.js", + { + "allExtensions": true, + "allowDeclareFields": true, + "allowNamespaces": true, + "isTSX": true, + "optimizeConstEnums": true, + }, + ], + ], + }, + }, + ], }, ], + "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, } `; @@ -364,88 +384,93 @@ exports[`plugins/babel > should set babel-loader when config is add 1`] = ` }, /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/plugin-babel/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, - }, - }, - }, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", }, { - "loader": "/packages/plugin-babel/compiled/babel-loader/index.js", - "options": { - "babelrc": false, - "cacheCompression": false, - "cacheDirectory": "/packages/plugin-babel/tests/node_modules/.cache/babel-loader", - "cacheIdentifier": "test", - "compact": false, - "configFile": false, - "plugins": [ - [ - "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", - { - "version": "2022-03", + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, }, - ], - [ - "babel-plugin-import", - { - "libraryDirectory": "es", - "libraryName": "my-components", - "style": true, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], }, - ], - ], - "presets": [ - [ - "/node_modules//@babel/preset-typescript/lib/index.js", - { - "allExtensions": true, - "allowDeclareFields": true, - "allowNamespaces": true, - "isTSX": true, - "optimizeConstEnums": true, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/plugin-babel/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, }, - ], - ], - }, + }, + }, + { + "loader": "/packages/plugin-babel/compiled/babel-loader/index.js", + "options": { + "babelrc": false, + "cacheCompression": false, + "cacheDirectory": "/packages/plugin-babel/tests/node_modules/.cache/babel-loader", + "cacheIdentifier": "test", + "compact": false, + "configFile": false, + "plugins": [ + [ + "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", + { + "version": "2022-03", + }, + ], + [ + "babel-plugin-import", + { + "libraryDirectory": "es", + "libraryName": "my-components", + "style": true, + }, + ], + ], + "presets": [ + [ + "/node_modules//@babel/preset-typescript/lib/index.js", + { + "allExtensions": true, + "allowDeclareFields": true, + "allowNamespaces": true, + "isTSX": true, + "optimizeConstEnums": true, + }, + ], + ], + }, + }, + ], }, ], + "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, } `; diff --git a/packages/plugin-react/tests/__snapshots__/index.test.ts.snap b/packages/plugin-react/tests/__snapshots__/index.test.ts.snap index d406985da5..d1c519d9ea 100644 --- a/packages/plugin-react/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-react/tests/__snapshots__/index.test.ts.snap @@ -19,60 +19,60 @@ exports[`plugins/react > should configuring \`tools.swc\` to override react runt /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, /\\[\\\\\\\\/\\]@rsbuild\\[\\\\\\\\/\\]core\\[\\\\\\\\/\\]dist\\[\\\\\\\\/\\]/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/plugin-react/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": true, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, - "react": { - "development": true, - "refresh": true, - "runtime": "classic", + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/plugin-react/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": true, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + "react": { + "development": true, + "refresh": true, + "runtime": "classic", + }, + }, }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, ] `; @@ -148,60 +148,60 @@ exports[`plugins/react > should work with swc-loader 1`] = ` /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, /\\[\\\\\\\\/\\]@rsbuild\\[\\\\\\\\/\\]core\\[\\\\\\\\/\\]dist\\[\\\\\\\\/\\]/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/plugin-react/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": true, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, - "react": { - "development": true, - "refresh": true, - "runtime": "automatic", + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/plugin-react/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": true, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + "react": { + "development": true, + "refresh": true, + "runtime": "automatic", + }, + }, }, }, }, - }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, ] `; diff --git a/packages/plugin-solid/tests/__snapshots__/index.test.ts.snap b/packages/plugin-solid/tests/__snapshots__/index.test.ts.snap index b6ffe721cd..49c0648fea 100644 --- a/packages/plugin-solid/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-solid/tests/__snapshots__/index.test.ts.snap @@ -2,113 +2,191 @@ exports[`plugin-solid > should allow to configure solid preset options 1`] = ` { - "module": { - "rules": [ - { - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "use": [ - { - "loader": "/packages/plugin-babel/compiled/babel-loader/index.js", - "options": { - "babelrc": false, - "compact": false, - "configFile": false, - "parserOpts": { - "plugins": [ - "jsx", - "typescript", - ], + "dependency": { + "not": "url", + }, + "include": [ + { + "not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/, + }, + /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, + ], + "oneOf": [ + { + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, + }, + }, + { + "loader": "/packages/plugin-babel/compiled/babel-loader/index.js", + "options": { + "babelrc": false, + "compact": false, + "configFile": false, + "parserOpts": { "plugins": [ - [ - "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", - { - "version": "2022-03", - }, - ], - [ - "/node_modules//solid-refresh/dist/babel.cjs", - ], - ], - "presets": [ - [ - "/node_modules//babel-preset-solid/index.js", - { - "generate": "ssr", - "hydratable": true, - }, - ], + "jsx", + "typescript", ], }, + "plugins": [ + [ + "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", + { + "version": "2022-03", + }, + ], + [ + "/node_modules//solid-refresh/dist/babel.cjs", + ], + ], + "presets": [ + [ + "/node_modules//babel-preset-solid/index.js", + { + "generate": "ssr", + "hydratable": true, + }, + ], + ], }, - ], - }, - ], - }, - "plugins": [ - { - "name": "RsbuildCorePlugin", + }, + ], }, ], - "resolve": { - "alias": { - "solid-refresh": "/node_modules//solid-refresh/dist/solid-refresh.mjs", - }, - }, + "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, } `; exports[`plugin-solid > should apply solid preset correctly 1`] = ` { - "module": { - "rules": [ - { - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "use": [ - { - "loader": "/packages/plugin-babel/compiled/babel-loader/index.js", - "options": { - "babelrc": false, - "compact": false, - "configFile": false, - "parserOpts": { - "plugins": [ - "jsx", - "typescript", - ], + "dependency": { + "not": "url", + }, + "include": [ + { + "not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/, + }, + /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, + ], + "oneOf": [ + { + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, + }, + }, + { + "loader": "/packages/plugin-babel/compiled/babel-loader/index.js", + "options": { + "babelrc": false, + "compact": false, + "configFile": false, + "parserOpts": { "plugins": [ - [ - "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", - { - "version": "2022-03", - }, - ], - [ - "/node_modules//solid-refresh/dist/babel.cjs", - ], - ], - "presets": [ - [ - "/node_modules//babel-preset-solid/index.js", - {}, - ], + "jsx", + "typescript", ], }, + "plugins": [ + [ + "/node_modules//@babel/plugin-proposal-decorators/lib/index.js", + { + "version": "2022-03", + }, + ], + [ + "/node_modules//solid-refresh/dist/babel.cjs", + ], + ], + "presets": [ + [ + "/node_modules//babel-preset-solid/index.js", + {}, + ], + ], }, - ], - }, - ], - }, - "plugins": [ - { - "name": "RsbuildCorePlugin", + }, + ], }, ], - "resolve": { - "alias": { - "solid-refresh": "/node_modules//solid-refresh/dist/solid-refresh.mjs", - }, - }, + "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, } `; diff --git a/packages/plugin-solid/tests/index.test.ts b/packages/plugin-solid/tests/index.test.ts index 010b5d5c47..eb2244c824 100644 --- a/packages/plugin-solid/tests/index.test.ts +++ b/packages/plugin-solid/tests/index.test.ts @@ -1,6 +1,6 @@ -import type { RsbuildConfig } from '@rsbuild/core'; +import { createRsbuild, type RsbuildConfig } from '@rsbuild/core'; import { pluginBabel } from '@rsbuild/plugin-babel'; -import { createStubRsbuild } from '@scripts/test-helper'; +import { matchRules } from '@scripts/test-helper'; import { pluginSolid } from '../src'; describe('plugin-solid', () => { @@ -11,30 +11,32 @@ describe('plugin-solid', () => { }; it('should apply solid preset correctly', async () => { - const rsbuild = await createStubRsbuild({ - config: rsbuildConfig, - plugins: [pluginSolid(), pluginBabel()], + const rsbuild = await createRsbuild({ + config: { + ...rsbuildConfig, + plugins: [pluginSolid(), pluginBabel()], + }, }); - const config = await rsbuild.unwrapConfig(); - - expect(config).toMatchSnapshot(); + const config = await rsbuild.initConfigs(); + expect(matchRules(config[0], 'a.tsx')[0]).toMatchSnapshot(); }); it('should allow to configure solid preset options', async () => { - const rsbuild = await createStubRsbuild({ - config: rsbuildConfig, - plugins: [ - pluginSolid({ - solidPresetOptions: { - generate: 'ssr', - hydratable: true, - }, - }), - pluginBabel(), - ], + const rsbuild = await createRsbuild({ + config: { + ...rsbuildConfig, + plugins: [ + pluginSolid({ + solidPresetOptions: { + generate: 'ssr', + hydratable: true, + }, + }), + pluginBabel(), + ], + }, }); - const config = await rsbuild.unwrapConfig(); - - expect(config).toMatchSnapshot(); + const config = await rsbuild.initConfigs(); + expect(matchRules(config[0], 'a.tsx')[0]).toMatchSnapshot(); }); }); diff --git a/packages/plugin-svelte/src/index.ts b/packages/plugin-svelte/src/index.ts index 4d84a2ff03..86759265ff 100644 --- a/packages/plugin-svelte/src/index.ts +++ b/packages/plugin-svelte/src/index.ts @@ -126,7 +126,10 @@ export function pluginSvelte(options: PluginSvelteOptions = {}): RsbuildPlugin { }; const jsRule = chain.module.rules.get(CHAIN_ID.RULE.JS); - const swcUse = jsRule.uses.get(CHAIN_ID.USE.SWC); + const jsTransformRule = jsRule.oneOfs.get( + CHAIN_ID.ONE_OF.JS_TRANSFORM, + ); + const swcUse = jsTransformRule.uses.get(CHAIN_ID.USE.SWC); const svelteRule = chain.module .rule(CHAIN_ID.RULE.SVELTE) .test(/\.svelte$/); diff --git a/packages/plugin-svelte/tests/__snapshots__/index.test.ts.snap b/packages/plugin-svelte/tests/__snapshots__/index.test.ts.snap index e8a2b17b17..20f9140ebe 100644 --- a/packages/plugin-svelte/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-svelte/tests/__snapshots__/index.test.ts.snap @@ -22,55 +22,55 @@ exports[`plugin-svelte > should add rule for \`.svelte.js\` and \`.svelte.ts\` a /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, /node_modules\\[\\\\\\\\/\\]svelte\\[\\\\\\\\/\\]/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/plugin-svelte/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, - }, - }, - }, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/plugin-svelte/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, + }, + }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "test": /\\\\\\.\\(\\?:svelte\\\\\\.js\\|svelte\\\\\\.ts\\)\\$/, @@ -148,55 +148,55 @@ exports[`plugin-svelte > should add rule for \`.svelte.js\` and \`.svelte.ts\` a /\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/, /node_modules\\[\\\\\\\\/\\]svelte\\[\\\\\\\\/\\]/, ], - "resourceQuery": { - "not": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, - }, - "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "javascript/auto", - "use": [ + "oneOf": [ { - "loader": "builtin:swc-loader", - "options": { - "collectTypeScriptInfo": { - "exportedEnum": false, - "typeExports": true, - }, - "env": { - "targets": [ - "chrome >= 107", - "edge >= 107", - "firefox >= 104", - "safari >= 16", - ], - }, - "isModule": "unknown", - "jsc": { - "experimental": { - "cacheRoot": "/packages/plugin-svelte/tests/node_modules/.cache/.swc", - "keepImportAttributes": true, - }, - "externalHelpers": true, - "output": { - "charset": "utf8", - }, - "parser": { - "decorators": true, - "syntax": "typescript", - "tsx": false, - }, - "transform": { - "decoratorVersion": "2022-03", - "legacyDecorator": false, - }, - }, - }, + "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, + "type": "asset/source", + }, + { + "type": "javascript/auto", + "use": [ + { + "loader": "builtin:swc-loader", + "options": { + "collectTypeScriptInfo": { + "exportedEnum": false, + "typeExports": true, + }, + "env": { + "targets": [ + "chrome >= 107", + "edge >= 107", + "firefox >= 104", + "safari >= 16", + ], + }, + "isModule": "unknown", + "jsc": { + "experimental": { + "cacheRoot": "/packages/plugin-svelte/tests/node_modules/.cache/.swc", + "keepImportAttributes": true, + }, + "externalHelpers": true, + "output": { + "charset": "utf8", + }, + "parser": { + "decorators": true, + "syntax": "typescript", + "tsx": false, + }, + "transform": { + "decoratorVersion": "2022-03", + "legacyDecorator": false, + }, + }, + }, + }, + ], }, ], - }, - { - "resourceQuery": /\\[\\?&\\]raw\\(\\?:&\\|=\\|\\$\\)/, "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, - "type": "asset/source", }, { "test": /\\\\\\.\\(\\?:svelte\\\\\\.js\\|svelte\\\\\\.ts\\)\\$/, diff --git a/packages/plugin-svgr/src/index.ts b/packages/plugin-svgr/src/index.ts index 8b184b37e2..05012e1310 100644 --- a/packages/plugin-svgr/src/index.ts +++ b/packages/plugin-svgr/src/index.ts @@ -268,9 +268,10 @@ export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({ // apply current JS transform rule to SVGR rules const jsRule = chain.module.rules.get(CHAIN_ID.RULE.JS); + const jsTransformRule = jsRule.oneOfs.get(CHAIN_ID.ONE_OF.JS_TRANSFORM); [CHAIN_ID.USE.SWC, CHAIN_ID.USE.BABEL].some((jsUseId) => { - const use = jsRule.uses.get(jsUseId); + const use = jsTransformRule.uses.get(jsUseId); if (!use) { return false;