swc-loader
这个模块允许你使用 SWC 与 webpack。
对于 Rspack 用户,你可以使用 Rspack 的 内置 swc-loader (opens in a new tab),而不需要安装 swc-loader 包。
安装
pnpm i -D @swc/core swc-loader
使用
webpack.config.js
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules)/,
use: {
// `.swcrc` can be used to configure swc
loader: "swc-loader"
}
}
]
}
选项
Loader 选项通过 SWC 传递,就像它们是 .swcrc
的一部分一样。
例如,配置 browserslist
-based targets
进行编译 (opens in a new tab) 并查看效果:
{
use: {
loader: "swc-loader",
options: {
env: {
targets: "defaults",
debug: true
}
}
}
}
React Development
The jsc.transform.react.development
option is automatically set based on the webpack mode
(opens in a new tab).
与 babel-loader 一起使用
当与 babel-loader 一起使用时,parseMap 选项必须设置为 true。
webpack.config.js
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules)/,
use: {
loader: "swc-loader",
options: {
parseMap: true
}
}
}
]
}