From bda1bb4cf53e7b9dd12d74e4eff416c80857e763 Mon Sep 17 00:00:00 2001 From: RiESAEX <2597245950@qq.com> Date: Wed, 8 Feb 2023 07:46:42 +0000 Subject: [PATCH] fix: minify --- .../plugins/commands/webpackConfig/index.js | 1 + .../commands/webpackConfig/minimizer.js | 21 ++-- .../commands/webpackConfig/swcOptions.js | 4 +- packages/fes-template/package.json | 2 +- yarn.lock | 108 +++++++++--------- 5 files changed, 72 insertions(+), 64 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 026f08c8..d834354e 100644 --- a/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/index.js +++ b/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/index.js @@ -319,6 +319,7 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod isProd, config, webpackConfig, + swcOptions: useSwc ? buildSwcOptions(targets, config, false, false, true) : undefined, }); // --------------- chainwebpack ----------- diff --git a/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/minimizer.js b/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/minimizer.js index 34ea0dc3..bf9343ea 100644 --- a/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/minimizer.js +++ b/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/minimizer.js @@ -38,15 +38,22 @@ const defaultTerserOptions = { }, }; -const terserOptions = (config) => ({ - terserOptions: deepmerge(defaultTerserOptions, config.terserOptions || {}), - extractComments: false, - minify: config.swcLoader ? TerserPlugin.swcMinify : undefined, -}); +const terserOptions = (config, swcOptions) => { + if (swcOptions) { + return { + terserOptions: swcOptions.jsc?.minify, + minify: TerserPlugin.swcMinify, + }; + } + return { + terserOptions: deepmerge(defaultTerserOptions, config.terserOptions || {}), + extractComments: false, + }; +}; -export default function createMinimizerWebpackConfig({ isProd, config, webpackConfig }) { +export default function createMinimizerWebpackConfig({ isProd, config, webpackConfig, swcOptions }) { if (isProd) { - webpackConfig.optimization.minimizer('terser').use(require.resolve('terser-webpack-plugin'), [terserOptions(config)]); + webpackConfig.optimization.minimizer('terser').use(require.resolve('terser-webpack-plugin'), [terserOptions(config, swcOptions)]); } if (process.env.FES_ENV === 'test') { webpackConfig.optimization.minimize(false); 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 503b98c9..e5654e36 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) { +export function buildSwcOptions(targets, config, isJsx, isTs, minify = false) { if (config.swcLoader?.cjsPkg) { delete config.swcLoader.cjsPkg; } @@ -26,7 +26,7 @@ export function buildSwcOptions(targets, config, isJsx, isTs) { // preserveAllComments: true, }, isModule: 'unknown', - minify: false, + minify: minify ? {} : false, }, config.swcLoader || {}, ); diff --git a/packages/fes-template/package.json b/packages/fes-template/package.json index c7ccc9ae..8b5ebda2 100644 --- a/packages/fes-template/package.json +++ b/packages/fes-template/package.json @@ -60,7 +60,7 @@ "@fesjs/plugin-vuex": "^3.0.0-rc.0", "@fesjs/plugin-watermark": "^3.0.0-rc.0", "@fesjs/plugin-windicss": "^3.0.0-rc.0", - "@swc/core": "^1.3.27", + "@swc/core": "^1.3.32", "core-js": "3.27.0", "pinia": "^2.0.11", "swc-plugin-vue-jsx": "^0.2.0", diff --git a/yarn.lock b/yarn.lock index c94612b6..72e55047 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2241,71 +2241,71 @@ magic-string "^0.25.0" string.prototype.matchall "^4.0.6" -"@swc/core-darwin-arm64@1.3.27": - version "1.3.27" - resolved "https://registry.npmmirror.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.27.tgz#247b275d505c2462ce08cca4e322becbca8e428a" - integrity sha512-IKlxkhEy99CnP9nduaf5IJWIFcr6D5cZCjYmCs7nWkjMV+aAieyDO9AX4LT8AcHy6CF7ByOX7SKoqk+gVMAaKw== +"@swc/core-darwin-arm64@1.3.32": + version "1.3.32" + resolved "https://registry.npmmirror.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.32.tgz#841b0a244c2c75e67bb9d3cb665b2ede601e4e3a" + integrity sha512-o19bhlxuUgjUElm6i+QhXgZ0vD6BebiB/gQpK3en5aAwhOvinwr4sah3GqFXsQzz/prKVDuMkj9SW6F/Ug5hgg== -"@swc/core-darwin-x64@1.3.27": - version "1.3.27" - resolved "https://registry.npmmirror.com/@swc/core-darwin-x64/-/core-darwin-x64-1.3.27.tgz#11090424c9bfd0d3e799abb06c1fa6a07abf5ed9" - integrity sha512-MtabZIhFf/dL3vs6UMbd+vJsjIkm2NaFqulGV0Jofy2bfVZPTj/b5pXeOlUsTWy7JcH1uixjdx4RvJRyvqJxQA== +"@swc/core-darwin-x64@1.3.32": + version "1.3.32" + resolved "https://registry.npmmirror.com/@swc/core-darwin-x64/-/core-darwin-x64-1.3.32.tgz#125247c6a5d7189776a6973b0a539a07576d5585" + integrity sha512-hVEGd+v5Afh+YekGADOGKwhuS4/AXk91nLuk7pmhWkk8ceQ1cfmah90kXjIXUlCe2G172MLRfHNWlZxr29E/Og== -"@swc/core-linux-arm-gnueabihf@1.3.27": - version "1.3.27" - resolved "https://registry.npmmirror.com/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.27.tgz#a41b40e056ed0887686e04a30b395521fe3f2d47" - integrity sha512-XELMoGcUTAkk+G4buwIIhu6AIr1U418Odt22HUW8+ZvV+Wty2ICgR/myOIhM3xMb6U2L8ay+evMqoVNMQ0RRTg== +"@swc/core-linux-arm-gnueabihf@1.3.32": + version "1.3.32" + resolved "https://registry.npmmirror.com/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.32.tgz#d8ba8da3707b91e62059e65e375fc6093c4d5f82" + integrity sha512-5X01WqI9EbJ69oHAOGlI08YqvEIXMfT/mCJ1UWDQBb21xWRE2W1yFAAeuqOLtiagLrXjPv/UKQ0S2gyWQR5AXQ== -"@swc/core-linux-arm64-gnu@1.3.27": - version "1.3.27" - resolved "https://registry.npmmirror.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.27.tgz#61705b0d534472a9dbde575594c61ef1377d0075" - integrity sha512-O6vtT6bnrVR9PzEIuA5U7tIfYo7bv97H9K9Vqy2oyHNeGN0H36DKwS4UqPreHtziXNF5+7ubdUYUkrG/j8UnUQ== +"@swc/core-linux-arm64-gnu@1.3.32": + version "1.3.32" + resolved "https://registry.npmmirror.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.32.tgz#15973e533c45e2976e57c590613e3e5dca0e62ad" + integrity sha512-PTJ6oPiutkNBg+m22bUUPa4tNuMmsgpSnsnv2wnWVOgK0lhvQT6bAPTUXDq/8peVAgR/SlpP2Ht8TRRqYMRjRQ== -"@swc/core-linux-arm64-musl@1.3.27": - version "1.3.27" - resolved "https://registry.npmmirror.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.27.tgz#4fb86dcf70b7fc1aba51d82bba00bb2c4134a980" - integrity sha512-Oa0E1i7dOTWpaEZumKoNbTE/Ap+da6nlhqKVUdYrFDrOBi25tz76SdxZIyvAszzmgY89b5yd1naourKmkPXpww== +"@swc/core-linux-arm64-musl@1.3.32": + version "1.3.32" + resolved "https://registry.npmmirror.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.32.tgz#0e20f30885c8588bd13e7e5628ce8bdbe6cb44b6" + integrity sha512-lG0VOuYNPWOCJ99Aza69cTljjeft/wuRQeYFF8d+1xCQS/OT7gnbgi7BOz39uSHIPTBqfzdIsuvzdKlp9QydrQ== -"@swc/core-linux-x64-gnu@1.3.27": - version "1.3.27" - resolved "https://registry.npmmirror.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.27.tgz#691cc341f8dd7f93a8e01044a2ad8b0e7111d65c" - integrity sha512-S3v9H8oL2a8Ur6AjQyhkC6HfBVPOxKMdBhcZmdNuVgEUHbHdbf/Lka85F9IOYXEarMn0FtQw3ywowS22O9L5Uw== +"@swc/core-linux-x64-gnu@1.3.32": + version "1.3.32" + resolved "https://registry.npmmirror.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.32.tgz#2ea5e17d13a70e6a13742282cf30e92e4074f4c5" + integrity sha512-ecqtSWX4NBrs7Ji2VX3fDWeqUfrbLlYqBuufAziCM27xMxwlAVgmyGQk4FYgoQ3SAUAu3XFH87+3Q7uWm2X7xg== -"@swc/core-linux-x64-musl@1.3.27": - version "1.3.27" - resolved "https://registry.npmmirror.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.27.tgz#a3e1c98513d6e8594c612ab3a671f10e2644dc2e" - integrity sha512-6DDkdXlOADpwICFZTRphCR+cIeS8aEYh4NlyzBito0mOWwIIdfCgALzhkTQOzTOkcD42bP97CIoZ97hqV/puOg== +"@swc/core-linux-x64-musl@1.3.32": + version "1.3.32" + resolved "https://registry.npmmirror.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.32.tgz#d96cde03d54f13f77dd1d6602a049bd2baaef446" + integrity sha512-rl3dMcUuENVkpk5NGW/LXovjK0+JFm4GWPjy4NM3Q5cPvhBpGwSeLZlR+zAw9K0fdGoIXiayRTTfENrQwwsH+g== -"@swc/core-win32-arm64-msvc@1.3.27": - version "1.3.27" - resolved "https://registry.npmmirror.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.27.tgz#70c173f78d3dfd97a0d99374d8f6d55b6fa1c4ef" - integrity sha512-baxfH4AbEcaTNo08wxV0W6hiMXwVCxPS4qc0amHpXPti92unvSqeDR1W3C9GjHqzXlWtmCRsq8Ww1pal6ZVLrw== +"@swc/core-win32-arm64-msvc@1.3.32": + version "1.3.32" + resolved "https://registry.npmmirror.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.32.tgz#3870113492cc3d2679945372f4975ce7f60594cc" + integrity sha512-VlybAZp8DcS66CH1LDnfp9zdwbPlnGXREtHDMHaBfK9+80AWVTg+zn0tCYz+HfcrRONqxbudwOUIPj+dwl/8jw== -"@swc/core-win32-ia32-msvc@1.3.27": - version "1.3.27" - resolved "https://registry.npmmirror.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.27.tgz#f34d40710da7939ea32c9a3a4334581468ae09aa" - integrity sha512-7iLJnH71k5qCwxv9NcM/P7nIEzTsC7r1sIiQW6bu+CpC8qZvwl0PS+XvQRlLly2gCZM+Le98tksYG14MEh+Hrw== +"@swc/core-win32-ia32-msvc@1.3.32": + version "1.3.32" + resolved "https://registry.npmmirror.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.32.tgz#643519663778e64941c8b730197d4ba762dffcb0" + integrity sha512-MEUMdpUFIQ+RD+K/iHhHKfu0TFNj9VXwIxT5hmPeqyboKo095CoFEFBJ0sHG04IGlnu8T9i+uE2Pi18qUEbFug== -"@swc/core-win32-x64-msvc@1.3.27": - version "1.3.27" - resolved "https://registry.npmmirror.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.27.tgz#f3b131d952808569d99dd4851e95910667743bd5" - integrity sha512-mFM907PDw/jrQ44+TRjIVGEOy2Mu06mMMz0HPMFuRsBzl5t0Kajp3vmn8FkkpS9wH5982VPi6hPYVTb7QJo5Qg== +"@swc/core-win32-x64-msvc@1.3.32": + version "1.3.32" + resolved "https://registry.npmmirror.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.32.tgz#aa9595cb93d9dd5bbc7e5cfdabd8bb086ea6c21d" + integrity sha512-DPMoneNFQco7SqmVVOUv1Vn53YmoImEfrAPMY9KrqQzgfzqNTuL2JvfxUqfAxwQ6pEKYAdyKJvZ483rIhgG9XQ== -"@swc/core@^1.3.27": - version "1.3.27" - resolved "https://registry.npmmirror.com/@swc/core/-/core-1.3.27.tgz#189da5fd132beba28106f5e5fcf43ce127c800dc" - integrity sha512-praRNgpeYGvwDIm/Cl6JU+yHMvwVraL0U6ejMgGyzvpcm1FVsZd1/EYXGqzbBJ0ALv7Gx4eK56h4GnwV6d4L0w== +"@swc/core@^1.3.32": + version "1.3.32" + resolved "https://registry.npmmirror.com/@swc/core/-/core-1.3.32.tgz#ecb3c9d7717e0a15796230def1b17968b18228f1" + integrity sha512-Yx/n1j+uUkcqlJAW8IRg8Qymgkdow6NHJZPFShiR0YiaYq2sXY+JHmvh16O6GkL91Y+gTlDUS7uVgDz50czJUQ== optionalDependencies: - "@swc/core-darwin-arm64" "1.3.27" - "@swc/core-darwin-x64" "1.3.27" - "@swc/core-linux-arm-gnueabihf" "1.3.27" - "@swc/core-linux-arm64-gnu" "1.3.27" - "@swc/core-linux-arm64-musl" "1.3.27" - "@swc/core-linux-x64-gnu" "1.3.27" - "@swc/core-linux-x64-musl" "1.3.27" - "@swc/core-win32-arm64-msvc" "1.3.27" - "@swc/core-win32-ia32-msvc" "1.3.27" - "@swc/core-win32-x64-msvc" "1.3.27" + "@swc/core-darwin-arm64" "1.3.32" + "@swc/core-darwin-x64" "1.3.32" + "@swc/core-linux-arm-gnueabihf" "1.3.32" + "@swc/core-linux-arm64-gnu" "1.3.32" + "@swc/core-linux-arm64-musl" "1.3.32" + "@swc/core-linux-x64-gnu" "1.3.32" + "@swc/core-linux-x64-musl" "1.3.32" + "@swc/core-win32-arm64-msvc" "1.3.32" + "@swc/core-win32-ia32-msvc" "1.3.32" + "@swc/core-win32-x64-msvc" "1.3.32" "@swc/css-android-arm-eabi@0.0.18": version "0.0.18"