From bca727338bc8220e7a8051609fdc1d75a37216fe Mon Sep 17 00:00:00 2001 From: RiESAEX <2597245950@qq.com> Date: Fri, 6 Jan 2023 08:56:44 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=AA=E5=9C=A8prod=E5=BC=80?= =?UTF-8?q?=E5=8E=8B=E7=BC=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/plugins/commands/webpackConfig/index.js | 12 ++++++------ .../src/plugins/commands/webpackConfig/swcOptions.js | 12 +++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) 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 || {}, );