diff --git a/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/index.js b/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/index.js index 409015d6..3af5292e 100644 --- a/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/index.js +++ b/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/index.js @@ -131,7 +131,7 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod .end() .use('swc-loader') .loader(require.resolve('swc-loader')) - .options(buildSwcOptions(targets, config, false, false, true)); + .options(buildSwcOptions(targets, config, false, false, true, false)); webpackConfig.module .rule('jsx') .test(/\.jsx$/) @@ -139,7 +139,7 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod .end() .use('swc-loader') .loader(require.resolve('swc-loader')) - .options(buildSwcOptions(targets, config, true, false, true)); + .options(buildSwcOptions(targets, config, true, false, true, false)); webpackConfig.module .rule('ts') @@ -148,7 +148,7 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod .end() .use('swc-loader') .loader(require.resolve('swc-loader')) - .options(buildSwcOptions(targets, config, false, true)); + .options(buildSwcOptions(targets, config, false, true, false)); webpackConfig.module .rule('tsx') .test(/\.tsx$/) @@ -156,7 +156,7 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod .end() .use('swc-loader') .loader(require.resolve('swc-loader')) - .options(buildSwcOptions(targets, config, true, true)); + .options(buildSwcOptions(targets, config, true, true, false)); // 为了避免第三方依赖包编译不充分导致线上问题,默认对 node_modules 也进行全编译,只在生产构建的时候进行 if (isProd) { const cjsReg = [/css-loader/].concat(config.swcLoader?.cjsPkg || []); @@ -178,7 +178,7 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod .end() .use('swc-loader') .loader(require.resolve('swc-loader')) - .options(buildSwcOptions(targets, config, false, false, true)); + .options(buildSwcOptions(targets, config, false, false, true, true)); webpackConfig.module .rule('cjs-in-node_modules') .test(/\.(js)$/) @@ -197,7 +197,7 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod .end() .use('swc-loader') .loader(require.resolve('swc-loader')) - .options(buildSwcOptions(targets, config, false, false, false)); + .options(buildSwcOptions(targets, config, false, false, false, true)); } } else { const babelOpts = await getBabelOpts({ diff --git a/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/swcOptions.js b/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/swcOptions.js index 3f262db3..b4672a84 100644 --- a/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/swcOptions.js +++ b/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/swcOptions.js @@ -1,6 +1,6 @@ import { deepmerge } from '@fesjs/utils'; -export function buildSwcOptions(targets, config, isJsx, isTs, isEsm) { +export function buildSwcOptions(targets, config, isJsx, isTs, isEsm, minify) { if (config.swcLoader?.cjsPkg) { delete config.swcLoader.cjsPkg; } @@ -17,15 +17,17 @@ export function buildSwcOptions(targets, config, isJsx, isTs, isEsm) { syntax: isTs ? 'typescript' : 'ecmascript', jsx: isJsx, }, - experimental: { - plugins: [['swc-plugin-vue-jsx', {}]], - }, + experimental: isJsx + ? { + plugins: [['swc-plugin-vue-jsx', {}]], + } + : undefined, // preserveAllComments: true, }, module: { type: isEsm ? 'es6' : 'commonjs', }, - // minify: true, + minify, }, config.swcLoader || {}, );