Skip to content

⚡️ SWC 编译 - 替代 Babel

安装

提示

  • @efox/emp-compile-swc 1.1.2后屏蔽 babel-plugin-import 支持,可以 import 样式解决
  • antd 5 切换到 css in js 后不再需要 babel-plugin-import
shell
pnpm i @efox/emp @efox/emp-compile-swc -D
pnpm i @efox/emp @efox/emp-compile-swc -D

配置

emp-config.js

js
const {defineConfig} = require('@efox/emp')
const compile = require('@efox/emp-compile-swc')//使用 swc进行 js、ts 编译
module.exports = defineConfig(() => {
  return {
    compile,
  }
})
const {defineConfig} = require('@efox/emp')
const compile = require('@efox/emp-compile-swc')//使用 swc进行 js、ts 编译
module.exports = defineConfig(() => {
  return {
    compile,
  }
})

package.json

json
...
  "scripts": {
    "dev": "emp dev",
    "build": "emp build",
    "start": "emp serve"
  },
...
...
  "scripts": {
    "dev": "emp dev",
    "build": "emp build",
    "start": "emp serve"
  },
...

问题QA

从目前观察 swc已经解决了 sourcemap 显示、代码压缩、兼容等等问题 具体包括:

  • class 赋值问题 如 link
  • js、ts 压缩报错问题
  • babel 转译不一致问题

更多问题 环境提交 PR

导读

Released under the MIT License.