diff --git a/packages/fes-builder-webpack/package.json b/packages/fes-builder-webpack/package.json index 5f9aec0d..fcfcb097 100644 --- a/packages/fes-builder-webpack/package.json +++ b/packages/fes-builder-webpack/package.json @@ -35,7 +35,6 @@ "@babel/preset-env": "^7.16.4", "@babel/preset-typescript": "^7.15.0", "@fesjs/utils": "3.0.0-rc.2", - "@swc/core": "^1.3.24", "@vue/babel-plugin-jsx": "^1.1.1", "autoprefixer": "^10.2.4", "babel-loader": "^8.2.2", @@ -45,7 +44,8 @@ "connect-history-api-fallback": "^1.6.0", "copy-webpack-plugin": "^7.0.0", "css-loader": "^5.0.1", - "css-minimizer-webpack-plugin": "^3.0.0", + "css-minimizer-webpack-plugin": "^4.0.0", + "swc-loader": "^0.2.3", "html-webpack-plugin": "^5.0.0", "html-webpack-tags-plugin": "^3.0.0", "less": "3.9.0", @@ -56,8 +56,6 @@ "postcss-loader": "^4.2.0", "postcss-safe-parser": "^6.0.0", "style-loader": "^2.0.0", - "swc-loader": "^0.2.3", - "swc-plugin-vue-jsx": "^0.2.0", "vue-loader": "^16.1.2", "webpack": "^5.69.0", "webpack-bundle-analyzer": "^4.4.0", diff --git a/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/css.js b/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/css.js index 5fad5ec9..1f0a3504 100644 --- a/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/css.js +++ b/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/css.js @@ -10,6 +10,7 @@ // 根据 entry 将文件输出到不同的文件夹 import { deepmerge } from '@fesjs/utils'; +import { CssMinimizerPlugin } from 'css-minimizer-webpack-plugin'; function createRules({ isDev, webpackConfig, config, lang, test, loader, options, browserslist, styleLoaderOption }) { function applyLoaders(rule, cssLoaderOption = {}) { @@ -97,7 +98,7 @@ export default function createCssWebpackConfig({ isDev, config, webpackConfig, b chunkFilename: '[id].[contenthash:8].css', }, ]); - webpackConfig.optimization.minimizer('css').use(require.resolve('css-minimizer-webpack-plugin'), [{}]); + webpackConfig.optimization.minimizer('css').use(require.resolve('css-minimizer-webpack-plugin'), [{ minify: CssMinimizerPlugin.swcMinify }]); } return (options) => { 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 fcdd8245..70324605 100644 --- a/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/swcOptions.js +++ b/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/swcOptions.js @@ -1,5 +1,5 @@ export function buildSwcOptions(browserslist, config, isJsx, isTs) { - return { + const result = { env: { targets: browserslist, mode: 'entry', @@ -10,11 +10,12 @@ export function buildSwcOptions(browserslist, config, isJsx, isTs) { syntax: isTs ? 'typescript' : 'ecmascript', jsx: isJsx, }, - experimental: { - plugins: [['swc-plugin-vue-jsx', {}]], - }, }, minify: true, ...config.swcLoader, }; + if (isJsx) { + result.jsc.parser.experimental.plugins = (result.jsc.parser.experimental.plugins || []).push(['swc-plugin-vue-jsx', {}]); + } + return result; } diff --git a/packages/fes-template/package.json b/packages/fes-template/package.json index 07c383a6..2d7cb31e 100644 --- a/packages/fes-template/package.json +++ b/packages/fes-template/package.json @@ -59,6 +59,8 @@ "@fesjs/plugin-pinia": "^3.0.0-rc.0", "@fesjs/plugin-watermark": "^3.0.0-rc.0", "@fesjs/fes-design": "^0.7.0", + "swc-plugin-vue-jsx": "^0.2.0", + "@swc/core": "^1.3.24", "vue": "^3.2.37", "vuex": "^4.0.0", "pinia": "^2.0.11"