in packages/shared-config/src/unPlugins/compilation.ts [182:263]
export function getJsxTransformOptions({
suffix,
fastRefresh,
polyfill,
enableEnv,
mode,
rootDir,
}: GetJsxTransformOptions) {
const reactTransformConfig: ReactConfig = {
// Swc won't enable fast refresh when development is false in the latest version.
development: mode === 'development',
refresh: fastRefresh,
runtime: 'automatic',
importSource: '@ice/runtime/react', // The exact import source is '@ice/runtime/react/jsx-runtime'
};
const commonOptions: SwcConfig = {
jsc: {
transform: {
react: reactTransformConfig,
legacyDecorator: true,
},
// This option will greatly reduce your file size while bundling.
// This option depends on `@swc/helpers`.
externalHelpers: true,
},
module: {
type: 'es6',
noInterop: false,
},
};
if (enableEnv) {
commonOptions.env = {
loose: false,
...(polyfill ? {
mode: polyfill,
coreJs: '3.32',
} : {}),
};
const supportBrowsers = getSupportedBrowsers(rootDir, mode === 'development');
if (supportBrowsers) {
// Fix issue of https://github.com/swc-project/swc/issues/3365
commonOptions.env.targets = supportBrowsers;
}
} else {
// Set target `es2022` for default transform when env is false.
commonOptions.jsc.target = 'es2022';
}
const syntaxFeatures = {
dynamicImport: true,
decorators: true,
privateMethod: true,
importMeta: true,
exportNamespaceFrom: true,
};
const jsOptions = merge({
jsc: {
parser: {
jsx: true,
...syntaxFeatures,
syntax: 'ecmascript',
},
},
}, commonOptions);
const tsOptions = merge({
jsc: {
parser: {
tsx: true,
...syntaxFeatures,
syntax: 'typescript',
},
},
}, commonOptions);
if (suffix === 'jsx') {
return jsOptions;
} else if (suffix === 'tsx') {
return tsOptions;
}
return commonOptions;
}