chore: update swc

This commit is contained in:
RiESAEX 2023-01-17 08:46:04 +00:00
parent bca727338b
commit b3555770a6
8 changed files with 84 additions and 102 deletions

View File

@ -57,6 +57,7 @@
"postcss-safe-parser": "^6.0.0",
"style-loader": "^2.0.0",
"swc-loader": "^0.2.3",
"terser-webpack-plugin": "^5.3.6",
"vue-loader": "^16.1.2",
"webpack": "^5.69.0",
"webpack-bundle-analyzer": "^4.4.0",

View File

@ -60,7 +60,7 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod
webpackConfig.mode(env);
webpackConfig.stats('errors-only');
webpackConfig.externals(config.externals || {});
webpackConfig.devtool(isDev ? config.devtool || 'cheap-module-source-map' : config.devtool);
webpackConfig.devtool(false);
// --------------- cache -----------
webpackConfig.cache({
@ -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, false));
.options(buildSwcOptions(targets, config, false, 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, false));
.options(buildSwcOptions(targets, config, 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, false));
.options(buildSwcOptions(targets, config, false, true));
webpackConfig.module
.rule('tsx')
.test(/\.tsx$/)
@ -156,13 +156,13 @@ 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, false));
.options(buildSwcOptions(targets, config, true, true));
// 为了避免第三方依赖包编译不充分导致线上问题,默认对 node_modules 也进行全编译,只在生产构建的时候进行
if (isProd) {
const cjsReg = [/css-loader/].concat(config.swcLoader?.cjsPkg || []);
// const cjsReg = [/css-loader/, /vue-loader/].concat(config.swcLoader?.cjsPkg || []);
const transpileDepRegex = genTranspileDepRegex(config.nodeModulesTransform.exclude);
webpackConfig.module
.rule('esm-in-node_modules')
.rule('node_modules')
.test(/\.(js|mjs)$/)
.include.add(/node_modules/)
.end()
@ -170,34 +170,12 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod
if (transpileDepRegex && transpileDepRegex.test(filepath)) {
return true;
}
if (cjsReg.some((reg) => reg.test(filepath))) {
return true;
}
return false;
})
.end()
.use('swc-loader')
.loader(require.resolve('swc-loader'))
.options(buildSwcOptions(targets, config, false, false, true, true));
webpackConfig.module
.rule('cjs-in-node_modules')
.test(/\.(js)$/)
.include.add(/node_modules/)
.end()
.exclude.add((filepath) => {
if (transpileDepRegex && transpileDepRegex.test(filepath)) {
return true;
}
if (cjsReg.every((reg) => !reg.test(filepath))) {
return true;
}
return false;
})
.end()
.use('swc-loader')
.loader(require.resolve('swc-loader'))
.options(buildSwcOptions(targets, config, false, false, false, true));
.options(buildSwcOptions(targets, config, false, false));
}
} else {
const babelOpts = await getBabelOpts({
@ -337,13 +315,12 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod
}
// --------------- 压缩 -----------
if (!useSwc) {
createMinimizerWebpackConfig({
isProd,
config,
webpackConfig,
});
}
createMinimizerWebpackConfig({
isProd,
config,
webpackConfig,
});
// --------------- chainwebpack -----------
if (chainWebpack) {
await chainWebpack(webpackConfig, {

View File

@ -1,4 +1,5 @@
import { deepmerge } from '@fesjs/utils';
import TerserPlugin from 'terser-webpack-plugin';
const defaultTerserOptions = {
compress: {
@ -40,6 +41,7 @@ const defaultTerserOptions = {
const terserOptions = (config) => ({
terserOptions: deepmerge(defaultTerserOptions, config.terserOptions || {}),
extractComments: false,
minify: config.swcLoader ? TerserPlugin.swcMinify : undefined,
});
export default function createMinimizerWebpackConfig({ isProd, config, webpackConfig }) {

View File

@ -1,6 +1,6 @@
import { deepmerge } from '@fesjs/utils';
export function buildSwcOptions(targets, config, isJsx, isTs, isEsm, minify) {
export function buildSwcOptions(targets, config, isJsx, isTs) {
if (config.swcLoader?.cjsPkg) {
delete config.swcLoader.cjsPkg;
}
@ -15,7 +15,8 @@ export function buildSwcOptions(targets, config, isJsx, isTs, isEsm, minify) {
jsc: {
parser: {
syntax: isTs ? 'typescript' : 'ecmascript',
jsx: isJsx,
jsx: isTs ? undefined : isJsx,
tsx: isTs ? isJsx : undefined,
},
experimental: isJsx
? {
@ -24,10 +25,8 @@ export function buildSwcOptions(targets, config, isJsx, isTs, isEsm, minify) {
: undefined,
// preserveAllComments: true,
},
module: {
type: isEsm ? 'es6' : 'commonjs',
},
minify,
isModule: 'unknown',
minify: false,
},
config.swcLoader || {},
);

View File

@ -1,6 +1,5 @@
// .fes.js 只负责管理编译时配置只能使用plain Object
export default {
publicPath: 'https://gw.alipayobjects.com/'
// publicPath: 'https://gw.alipayobjects.com/'
};

View File

@ -7,7 +7,8 @@
"prod": "FES_ENV=prod fes build",
"analyze": "ANALYZE=1 fes build",
"dev": "fes dev",
"test": "fes test"
"test": "fes test",
"prev": "fes preview"
},
"keywords": [
"管理端",
@ -59,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.24",
"@swc/core": "^1.3.27",
"core-js": "3.27.0",
"pinia": "^2.0.11",
"swc-plugin-vue-jsx": "^0.2.0",

View File

@ -0,0 +1,3 @@
export function f() {
console.log('a');
}

110
yarn.lock
View File

@ -2241,71 +2241,71 @@
magic-string "^0.25.0"
string.prototype.matchall "^4.0.6"
"@swc/core-darwin-arm64@1.3.24":
version "1.3.24"
resolved "https://registry.npmmirror.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.24.tgz#d41fc574cb5049def9001903680fdd924f065052"
integrity sha512-rR+9UpWm+fGXcipsjCst2hIL1GYIbo0YTLhJZWdIpQD6KRHHJMFXiydMgQQkDj2Ml7HpqUVgxj6m4ZWYL8b0OA==
"@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-x64@1.3.24":
version "1.3.24"
resolved "https://registry.npmmirror.com/@swc/core-darwin-x64/-/core-darwin-x64-1.3.24.tgz#0f7a3960b91cbd7f95f25542b29d0e08bde4f59d"
integrity sha512-px+5vkGtgPH0m3FkkTBHynlRdS5rRz+lK+wiXIuBZFJSySWFl6RkKbvwkD+sf0MpazQlqwlv/rTOGJBw6oDffg==
"@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-linux-arm-gnueabihf@1.3.24":
version "1.3.24"
resolved "https://registry.npmmirror.com/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.24.tgz#a0fdd97b8341806b57290217830a5d1ab7d0b193"
integrity sha512-jLs8ZOdTV4UW4J12E143QJ4mOMONQtqgAnuhBbRuWFzQ3ny1dfoC3P1jNWAJ2Xi59XdxAIXn0PggPNH4Kh34kw==
"@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-arm64-gnu@1.3.24":
version "1.3.24"
resolved "https://registry.npmmirror.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.24.tgz#0536d03e12dd471ebafc180599488404aebb65cf"
integrity sha512-A/v0h70BekrwGpp1DlzIFGcHQ3QQ2PexXcnnuIBZeMc9gNmHlcZmg3EcwAnaUDiokhNuSUFA/wV94yk1OqmSkw==
"@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-musl@1.3.24":
version "1.3.24"
resolved "https://registry.npmmirror.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.24.tgz#54f46ffea1bf6ffcbe7c62037efaefdfb5115214"
integrity sha512-pbc9eArWPTiMrbpS/pJo0IiQNAKAQBcBIDjWBGP1tcw2iDXYLw4bruwz9kI/VjakbshWb8MoE4T5ClkeuULvSw==
"@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-x64-gnu@1.3.24":
version "1.3.24"
resolved "https://registry.npmmirror.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.24.tgz#c2b5cef83f8afd2a57d0eafbac083562d50cd0e6"
integrity sha512-pP5pOLlY1xd352qo7rTlpVPUI9/9VhOd4b3Lk+LzfZDq9bTL2NDlGfyrPiwa5DGHMSzrugH56K2J68eutkxYVA==
"@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-musl@1.3.24":
version "1.3.24"
resolved "https://registry.npmmirror.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.24.tgz#3459d01f9bf745568a4196c1993987f3d4a98303"
integrity sha512-phNbP7zGp+Wcyxq1Qxlpe5KkxO7WLT2kVQUC7aDFGlVdCr+xdXsfH1MzheHtnr0kqTVQX1aiM8XXXHfFxR0oNA==
"@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-win32-arm64-msvc@1.3.24":
version "1.3.24"
resolved "https://registry.npmmirror.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.24.tgz#85a18c844c00d66bf46db99d9c98e9550b4d28f5"
integrity sha512-qhbiJTWAOqyR+K9xnGmCkOWSz2EmWpDBstEJCEOTc6FZiEdbiTscDmqTcMbCKaTHGu8t+6erVA4t65/Eg6uWPA==
"@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-ia32-msvc@1.3.24":
version "1.3.24"
resolved "https://registry.npmmirror.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.24.tgz#18318199ba06cab4ead8f6122b9f30b3f452b1e7"
integrity sha512-JfghIlscE4Rz+Lc08lSoDh+R0cWxrISed5biogFfE6vZqhaDnw3E5Qshqw7O3pIaiq8L2u1nmzuyP581ZmpbRA==
"@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-x64-msvc@1.3.24":
version "1.3.24"
resolved "https://registry.npmmirror.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.24.tgz#b53746787e5af021787134d393fd67b0431f90d9"
integrity sha512-3AmJRr0hwciwDBbzUNqaftvppzS8v9X/iv/Wl7YaVLBVpPfQvaZzfqLycvNMGLZb5vIKXR/u58txg3dRBGsJtw==
"@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@^1.3.24":
version "1.3.24"
resolved "https://registry.npmmirror.com/@swc/core/-/core-1.3.24.tgz#ef6b30267c1bbd48af62cbc91370fe9b3f5d6a23"
integrity sha512-QMOTd0AgiUT3K1crxLRqd3gw0f3FC8hhH1vvlIlryvYqU4c+FJ/T2G4ZhMKLxQlZ/jX6Rhk0gKINZRBxy2GFyQ==
"@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==
optionalDependencies:
"@swc/core-darwin-arm64" "1.3.24"
"@swc/core-darwin-x64" "1.3.24"
"@swc/core-linux-arm-gnueabihf" "1.3.24"
"@swc/core-linux-arm64-gnu" "1.3.24"
"@swc/core-linux-arm64-musl" "1.3.24"
"@swc/core-linux-x64-gnu" "1.3.24"
"@swc/core-linux-x64-musl" "1.3.24"
"@swc/core-win32-arm64-msvc" "1.3.24"
"@swc/core-win32-ia32-msvc" "1.3.24"
"@swc/core-win32-x64-msvc" "1.3.24"
"@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/css-android-arm-eabi@0.0.18":
version "0.0.18"
@ -10800,7 +10800,7 @@ terminal-link@^2.0.0:
ansi-escapes "^4.2.1"
supports-hyperlinks "^2.0.0"
terser-webpack-plugin@^5.1.3:
terser-webpack-plugin@^5.1.3, terser-webpack-plugin@^5.3.6:
version "5.3.6"
resolved "https://registry.npmmirror.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.6.tgz#5590aec31aa3c6f771ce1b1acca60639eab3195c"
integrity sha512-kfLFk+PoLUQIbLmB1+PZDMRSZS99Mp+/MHqDNmMA6tOItzRt+Npe3E+fsMs5mfcM0wCtrrdU387UnV+vnSffXQ==