diff --git a/packages/fes-builder-webpack/package.json b/packages/fes-builder-webpack/package.json index fcfcb097..9ff7c0cc 100644 --- a/packages/fes-builder-webpack/package.json +++ b/packages/fes-builder-webpack/package.json @@ -35,6 +35,7 @@ "@babel/preset-env": "^7.16.4", "@babel/preset-typescript": "^7.15.0", "@fesjs/utils": "3.0.0-rc.2", + "@swc/css": "^0.0.18", "@vue/babel-plugin-jsx": "^1.1.1", "autoprefixer": "^10.2.4", "babel-loader": "^8.2.2", @@ -45,7 +46,6 @@ "copy-webpack-plugin": "^7.0.0", "css-loader": "^5.0.1", "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,6 +56,7 @@ "postcss-loader": "^4.2.0", "postcss-safe-parser": "^6.0.0", "style-loader": "^2.0.0", + "swc-loader": "^0.2.3", "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/index.js b/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/index.js index 7c9aecc1..dc16ae5a 100644 --- a/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/index.js +++ b/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/index.js @@ -131,29 +131,26 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod .end() .use('swc-loader') .loader(require.resolve('swc-loader')) - .options(buildSwcOptions(browserslist, config, false, false)); + .options(buildSwcOptions(targets, config, false, false)); webpackConfig.module .rule('jsx') .test(/\.jsx$/) - .end() .use('swc-loader') .loader(require.resolve('swc-loader')) - .options(buildSwcOptions(browserslist, config, true, false)); + .options(buildSwcOptions(targets, config, true, false)); webpackConfig.module .rule('ts') .test(/\.ts$/) - .end() .use('swc-loader') .loader(require.resolve('swc-loader')) - .options(buildSwcOptions(browserslist, config, false, true)); + .options(buildSwcOptions(targets, config, false, true)); webpackConfig.module .rule('tsx') .test(/\.tsx$/) - .end() .use('swc-loader') .loader(require.resolve('swc-loader')) - .options(buildSwcOptions(browserslist, config, true, true)); + .options(buildSwcOptions(targets, config, true, true)); // 为了避免第三方依赖包编译不充分导致线上问题,默认对 node_modules 也进行全编译,只在生产构建的时候进行 if (isProd) { const transpileDepRegex = genTranspileDepRegex(config.nodeModulesTransform.exclude); @@ -172,7 +169,7 @@ export default async function getConfig({ api, cwd, config, env, entry = {}, mod .end() .use('swc-loader') .loader(require.resolve('swc-loader')) - .options(buildSwcOptions(browserslist, config, false, false)); + .options(buildSwcOptions(targets, config, false, false)); } } 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 70324605..9be21c92 100644 --- a/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/swcOptions.js +++ b/packages/fes-builder-webpack/src/plugins/commands/webpackConfig/swcOptions.js @@ -1,21 +1,24 @@ -export function buildSwcOptions(browserslist, config, isJsx, isTs) { - const result = { - env: { - targets: browserslist, - mode: 'entry', - coreJs: '3', - }, - jsc: { - parser: { - syntax: isTs ? 'typescript' : 'ecmascript', - jsx: isJsx, +import { deepmerge } from '@fesjs/utils'; + +export function buildSwcOptions(targets, config, isJsx, isTs) { + return deepmerge( + { + env: { + targets, + mode: 'usage', + coreJs: '3', }, + jsc: { + parser: { + syntax: isTs ? 'typescript' : 'ecmascript', + jsx: isJsx, + }, + experimental: { + plugins: [['swc-plugin-vue-jsx', {}]], + }, + }, + minify: true, }, - minify: true, - ...config.swcLoader, - }; - if (isJsx) { - result.jsc.parser.experimental.plugins = (result.jsc.parser.experimental.plugins || []).push(['swc-plugin-vue-jsx', {}]); - } - return result; + config.swcLoader || {}, + ); } diff --git a/packages/fes-preset-built-in/src/plugins/features/targets.js b/packages/fes-preset-built-in/src/plugins/features/targets.js index 592d97ec..31e79a8a 100644 --- a/packages/fes-preset-built-in/src/plugins/features/targets.js +++ b/packages/fes-preset-built-in/src/plugins/features/targets.js @@ -5,7 +5,7 @@ export default (api) => { default: { chrome: '64', ios: '11', - browsers: ['defaults and not chrome < 61'], + // browsers: ['defaults and not chrome < 61'], }, schema(joi) { return joi.object(); diff --git a/packages/fes-template/.fes.js b/packages/fes-template/.fes.js index 91e89578..be3cdbbc 100644 --- a/packages/fes-template/.fes.js +++ b/packages/fes-template/.fes.js @@ -1,7 +1,14 @@ import { defineBuildConfig } from '@fesjs/fes'; export default defineBuildConfig({ - swcLoader: {}, + swcLoader: { + env: { + coreJs: '3.27', + }, + }, + targets: { + chrome: '78', + }, define: { __DEV__: false, }, diff --git a/packages/fes-template/package.json b/packages/fes-template/package.json index 2d7cb31e..eab5c1a1 100644 --- a/packages/fes-template/package.json +++ b/packages/fes-template/package.json @@ -44,26 +44,27 @@ }, "dependencies": { "@fesjs/fes": "^3.0.0-rc.0", + "@fesjs/fes-design": "^0.7.0", "@fesjs/plugin-access": "^3.0.0-rc.0", + "@fesjs/plugin-enums": "^3.0.0-rc.0", + "@fesjs/plugin-jest": "^2.0.0", "@fesjs/plugin-layout": "^5.0.0-rc.0", "@fesjs/plugin-locale": "^4.0.0-rc.0", "@fesjs/plugin-model": "^3.0.0-rc.0", - "@fesjs/plugin-enums": "^3.0.0-rc.0", - "@fesjs/plugin-jest": "^2.0.0", - "@fesjs/plugin-vuex": "^3.0.0-rc.0", - "@fesjs/plugin-request": "^3.0.0-rc.0", - "@fesjs/plugin-qiankun": "^3.0.0-rc.0", - "@fesjs/plugin-sass": "^3.0.0-rc.0", "@fesjs/plugin-monaco-editor": "^3.0.0-rc.0", - "@fesjs/plugin-windicss": "^3.0.0-rc.0", "@fesjs/plugin-pinia": "^3.0.0-rc.0", + "@fesjs/plugin-qiankun": "^3.0.0-rc.0", + "@fesjs/plugin-request": "^3.0.0-rc.0", + "@fesjs/plugin-sass": "^3.0.0-rc.0", + "@fesjs/plugin-vuex": "^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", + "@fesjs/plugin-windicss": "^3.0.0-rc.0", "@swc/core": "^1.3.24", + "core-js": "3.27.0", + "pinia": "^2.0.11", + "swc-plugin-vue-jsx": "^0.2.0", "vue": "^3.2.37", - "vuex": "^4.0.0", - "pinia": "^2.0.11" + "vuex": "^4.0.0" }, "private": true -} \ No newline at end of file +} diff --git a/packages/fes-template/src/pages/index.vue b/packages/fes-template/src/pages/index.vue index 41275d99..9abfa8b7 100644 --- a/packages/fes-template/src/pages/index.vue +++ b/packages/fes-template/src/pages/index.vue @@ -1,5 +1,5 @@