@modern-js/main-doc 0.0.0-nightly-20240911170726 → 0.0.0-nightly-20240912170717
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,6 +37,37 @@ export default defineConfig<'rspack'>({
|
|
37
37
|
|
38
38
|
For more usage, please refer to [Rsbuild - tools.swc](https://rsbuild.dev/config/tools/swc).
|
39
39
|
|
40
|
+
### Register SWC Plugin
|
41
|
+
|
42
|
+
Modern.js supports registering SWC's Wasm plugin through `tools.swc`, such as registering [@swc/plugin-styled-components](https://www.npmjs.com/package/@swc/plugin-styled-components):
|
43
|
+
|
44
|
+
```ts
|
45
|
+
export default {
|
46
|
+
tools: {
|
47
|
+
swc: {
|
48
|
+
jsc: {
|
49
|
+
experimental: {
|
50
|
+
plugins: [['@swc/plugin-styled-components', {}]],
|
51
|
+
},
|
52
|
+
},
|
53
|
+
},
|
54
|
+
},
|
55
|
+
};
|
56
|
+
```
|
57
|
+
|
58
|
+
Please note that the SWC plugin is still an experimental feature, and the SWC Wasm plugin is currently not backward compatible. The version of the SWC plugin is closely tied to the version of swc_core that Rspack depends on.
|
59
|
+
|
60
|
+
This means that you must to choose an SWC plugin that matches the current version of swc_core to ensure that it works properly. If the version of the SWC plugin you are using does not match the version of swc_core that Rspack depends on, Rspack will throw the following error during the build process:
|
61
|
+
|
62
|
+
```
|
63
|
+
1: failed to run Wasm plugin transform. Please ensure the version of `swc_core`
|
64
|
+
used by the plugin is compatible with the host runtime.
|
65
|
+
```
|
66
|
+
|
67
|
+
If you encounter the above issues, a common solution is to upgrade both the Modern.js and SWC plugins to the latest versions.
|
68
|
+
|
69
|
+
For details, please refer to [Rsbuild - SWC Plugin Version](https://rsbuild.dev/guide/basic/configure-swc#swc-plugin-version).
|
70
|
+
|
40
71
|
## Used in Webpack mode
|
41
72
|
|
42
73
|
import EnableSWC from '@modern-js/builder-doc/docs/en/shared/enableSwc.md';
|
@@ -37,6 +37,37 @@ export default defineConfig<'rspack'>({
|
|
37
37
|
|
38
38
|
更多用法可参考 [Rsbuild - tools.swc](https://rsbuild.dev/zh/config/tools/swc)。
|
39
39
|
|
40
|
+
### 注册 SWC 插件
|
41
|
+
|
42
|
+
Modern.js 支持通过 `tools.swc` 注册 SWC 的 Wasm 插件,比如注册 [@swc/plugin-styled-components](https://www.npmjs.com/package/@swc/plugin-styled-components):
|
43
|
+
|
44
|
+
```ts
|
45
|
+
export default {
|
46
|
+
tools: {
|
47
|
+
swc: {
|
48
|
+
jsc: {
|
49
|
+
experimental: {
|
50
|
+
plugins: [['@swc/plugin-styled-components', {}]],
|
51
|
+
},
|
52
|
+
},
|
53
|
+
},
|
54
|
+
},
|
55
|
+
};
|
56
|
+
```
|
57
|
+
|
58
|
+
需要注意的是,SWC 的插件仍然是一个实验性功能,目前 SWC 的 Wasm 插件是不向后兼容的,SWC 插件的版本与 Rspack 依赖的 swc_core 版本存在强耦合关系。
|
59
|
+
|
60
|
+
这意味着,你需要选择和当前 swc_core 版本匹配的 SWC 插件,才能使它正常执行。如果你使用的 SWC 插件版本与 Rspack 依赖的 swc_core 版本不匹配,Rspack 在执行构建时会抛出如下错误:
|
61
|
+
|
62
|
+
```
|
63
|
+
1: failed to run Wasm plugin transform. Please ensure the version of `swc_core`
|
64
|
+
used by the plugin is compatible with the host runtime.
|
65
|
+
```
|
66
|
+
|
67
|
+
如果你遇到了以上问题,通常可行的解决方法是将 Modern.js 和 SWC 插件都升级到最新版本。
|
68
|
+
|
69
|
+
详情可参考 [Rsbuild - SWC 插件版本](https://rsbuild.dev/zh/guide/basic/configure-swc#swc-%E6%8F%92%E4%BB%B6%E7%89%88%E6%9C%AC)。
|
70
|
+
|
40
71
|
## 在 Webpack 模式下使用
|
41
72
|
|
42
73
|
import EnableSWC from '@modern-js/builder-doc/docs/zh/shared/enableSwc.md';
|
package/package.json
CHANGED
@@ -15,20 +15,20 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "0.0.0-nightly-
|
18
|
+
"version": "0.0.0-nightly-20240912170717",
|
19
19
|
"publishConfig": {
|
20
20
|
"registry": "https://registry.npmjs.org/",
|
21
21
|
"access": "public",
|
22
22
|
"provenance": true
|
23
23
|
},
|
24
24
|
"dependencies": {
|
25
|
-
"@modern-js/sandpack-react": "0.0.0-nightly-
|
25
|
+
"@modern-js/sandpack-react": "0.0.0-nightly-20240912170717"
|
26
26
|
},
|
27
27
|
"peerDependencies": {
|
28
|
-
"@modern-js/builder-doc": "0.0.0-nightly-
|
28
|
+
"@modern-js/builder-doc": "0.0.0-nightly-20240912170717"
|
29
29
|
},
|
30
30
|
"devDependencies": {
|
31
|
-
"@rspress/shared": "1.
|
31
|
+
"@rspress/shared": "1.31.0",
|
32
32
|
"@types/fs-extra": "9.0.13",
|
33
33
|
"@types/node": "^16",
|
34
34
|
"classnames": "^2",
|
@@ -36,10 +36,10 @@
|
|
36
36
|
"fs-extra": "^10",
|
37
37
|
"react": "^18",
|
38
38
|
"react-dom": "^18",
|
39
|
-
"rspress": "1.
|
39
|
+
"rspress": "1.31.0",
|
40
40
|
"ts-node": "^10.9.1",
|
41
41
|
"typescript": "^5",
|
42
|
-
"@modern-js/builder-doc": "0.0.0-nightly-
|
42
|
+
"@modern-js/builder-doc": "0.0.0-nightly-20240912170717"
|
43
43
|
},
|
44
44
|
"scripts": {
|
45
45
|
"dev": "rspress dev",
|