You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/document/builder-doc/docs/en/plugins/plugin-swc.mdx
+32-6Lines changed: 32 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,37 @@ import SWC from '@en/shared/swc.md';
4
4
5
5
<SWC />
6
6
7
-
## Quick Start
7
+
## Usage Scenarios
8
8
9
-
:::tip
10
-
When using Rspack as the bundler, SWC will be used for transpiling and compression by default, so you don't need to install or configure the SWC plugin.
11
-
:::
9
+
Before using the SWC plugin, please understand the scenarios and limitations of the SWC plugin to determine whether your project is suitable for using it.
10
+
11
+
### Rspack Scenario
12
+
13
+
If you are already using Rspack as the bundler in your project, then you do not need to use the SWC plugin, because Rspack uses SWC for transpiler and minifier by default, and the SWC compilation capabilities are available out of the box.
14
+
15
+
### Babel Plugins
16
+
17
+
If your project requires the registration of some custom Babel plugins, you will not be able to register and use Babel plugins after using SWC, since it replaces Babel as the transpiler.
18
+
19
+
For most common Babel plugins, you can find corresponding replacements in SWC, such as:
20
+
21
+
-`@babel/preset-env`: use [presetEnv](#presetenv) instead.
22
+
-`@babel/preset-react`: use [presetReact](#presetreact) instead.
23
+
-`babel-plugin-import`: use [source.transformImport](/api/config-source.html#sourcetransformimport) instead.
24
+
-`babel-plugin-lodash`: use [extensions.lodash](#extensionslodash) instead.
25
+
-`@emotion/babel-plugin`: use [extensions.emotion](#extensionsemotion) instead.
26
+
-`babel-plugin-styled-components`: use [extensions.styledComponent](#extensionsstyledcomponent) instead.
27
+
-`@babel/plugin-react-transform-remove-prop-types`: use [reactUtils.removePropTypes](#extensionsreactutils) instead.
28
+
29
+
If you use Babel plugin capabilities that are not yet supported by SWC, you will no longer be able to use them after switching to SWC compilation. You can give feedback via issues under the [swc-plugins](https://github.com/web-infra-dev/swc-plugins) repository and we will evaluate if built-in support is needed.
30
+
31
+
### Bundle Size
32
+
33
+
When using SWC for code minification instead of [terser](https://github.com/terser/terser) and [cssnano](https://github.com/cssnano/cssnano), there may be a small change in the bundle size. SWC outperforms terser for JavaScript code compression and slightly underperforms cssnano for CSS code compression.
34
+
35
+
For a detailed comparison between minifiers, see [minification-benchmarks](https://github.com/privatenumber/minification-benchmarks).
36
+
37
+
## Quick Start
12
38
13
39
### Install
14
40
@@ -161,7 +187,7 @@ Remove `React` runtime type checking. This is ported from [@babel/plugin-react-t
161
187
-**Type:**`{ cwd?: string; ids?: string;}`
162
188
-**Default:**`{ cwd: process.cwd(), ids: [] }`
163
189
164
-
Ported from [@babel/plugin-lodash](https://github.com/lodash/babel-plugin-lodash).
190
+
Ported from [babel-plugin-lodash](https://github.com/lodash/babel-plugin-lodash).
165
191
166
192
#### extensions.styledComponent
167
193
@@ -187,7 +213,7 @@ boolean | {
187
213
};
188
214
```
189
215
190
-
This is ported by Next.js team from [styled-component](https://github.com/styled-components/babel-plugin-styled-components).
216
+
This is ported by Next.js team from [babel-plugin-styled-components](https://github.com/styled-components/babel-plugin-styled-components).
0 commit comments