Skip to content
开发文档
Usage
swc-loader

swc-loader

该模块允许你将 SWC 与 webpack 一起使用。

¥This module allows you to use SWC with webpack.

安装

¥Installation

pnpm i -D @swc/core swc-loader

用法

¥Usage

webpack.config.js
module: {
  rules: [
    {
      test: /\.m?js$/,
      exclude: /(node_modules)/,
      use: {
        // `.swcrc` can be used to configure swc
        loader: "swc-loader"
      }
    }
  ]
}

React 开发

¥React Development

jsc.transform.react.development 选项是根据 Webpack mode (opens in a new tab) 自动设置的。

¥The jsc.transform.react.development option is automatically set based on the webpack mode (opens in a new tab).

使用 babel-loader

¥With babel-loader

当与 babel-loader 一起使用时,parseMap 选项必须设置为 true。

¥When used with babel-loader, the parseMap option must be set to true.

webpack.config.js
module: {
  rules: [
    {
      test: /\.m?js$/,
      exclude: /(node_modules)/,
      use: {
        loader: "swc-loader",
        options: {
          parseMap: true
        }
      }
    }
  ]
}
Last updated on November 24, 2023