Skip to content

Commit e726bbb

Browse files
committed
fix
1 parent ba30772 commit e726bbb

File tree

4 files changed

+56
-26
lines changed

4 files changed

+56
-26
lines changed

pnpm-lock.yaml

Lines changed: 2 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Rslib could reuse the plugins from Rsbuild, which means the [official plugins](h
6565
| -------------------------------------- | ------ | ----------------------------------------------------------------------------- |
6666
| @modern-js/plugin-module-import | 🟢 | Use https://rsbuild.dev/config/source/transform-import#sourcetransformimport. |
6767
| @modern-js/plugin-module-banner | 🟢 | BannerPlugin. |
68-
| @modern-js/plugin-module-node-polyfill | ⚪️ | Use https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill. |
68+
| @modern-js/plugin-module-node-polyfill | 🟢 | Use https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill. |
6969
| @modern-js/plugin-module-polyfill | ⚪️ | Use https://rsbuild.dev/config/output/polyfill#outputpolyfill. |
7070
| @modern-js/plugin-module-babel | 🟢 | Use https://rsbuild.dev/plugins/list/plugin-babel. |
7171
| @modern-js/plugin-module-vue | ⚪️ | Use https://rsbuild.dev/plugins/list/plugin-vue. |

website/docs/en/guide/advanced/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"dts",
99
"module-federation",
1010
"module-doc",
11+
"node-polyfill",
1112
"storybook",
1213
"monorepo"
1314
]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { Steps, SourceCode } from '@theme';
2+
import { PackageManagerTabs } from '@theme';
3+
4+
# Node Polyfill
5+
6+
:::tip About Node Polyfill
7+
Normally, we don't need to use Node libs on the browser side. However, it is possible to use some Node libs when the code will run on both the Node side and the browser side, and Node Polyfill provides browser versions of polyfills for these Node libs.
8+
:::
9+
10+
By using [@rsbuild/plugin-node-polyfill](https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill), Node core libs polyfills are automatically injected into the browser-side, allowing you to use these modules on the browser side with confidence.
11+
12+
## Getting Start
13+
14+
<Steps>
15+
16+
### Install plugin
17+
18+
Rslib uses [@rsbuild/plugin-node-polyfill](https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill) to provide the Node Polyfill feature.
19+
20+
<PackageManagerTabs command="@rsbuild/plugin-node-polyfill -D" />
21+
22+
### Register plugin
23+
24+
Add the plugin into the plugins field.
25+
26+
```ts
27+
import { defineConfig } from '@rslib/core';
28+
import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill';
29+
30+
export default defineConfig({
31+
lib: [{ format: 'esm' }],
32+
plugins: [pluginNodePolyfill()],
33+
});
34+
```
35+
36+
### Setup
37+
38+
- For projects with `bundle` enabled, the Node Polyfill will be injected and included in the output.
39+
- For projects with `bundle` disabled, polyfills are not injected into the output by default. To avoid inlining the polyfill in every module. The modules are externalized and need to be added to dependencies manually, follow these steps:
40+
41+
1. Configure `output.external` with `resolvedPolyfillToModules`, which you can import from [@rsbuild/plugin-node-polyfill](https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill). This will externalize the polyfill modules to the installed polyfill dependencies.
42+
2. Install used polyfill modules as dependencies.
43+
44+
With the following steps, every usage of the polyfill module will be replaced by the corresponding module in the `externals` field. Checkout the <SourceCode href="https://github.com/web-infra-dev/rslib/blob/main/tests/integration/node-polyfill/bundle-false/rslib.config.ts" /> of the example for more details.
45+
46+
</Steps>
47+
48+
###
49+
50+
## Configurations
51+
52+
Check out the documentation of [@rsbuild/plugin-node-polyfill](https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill), all the configurations are applicable for Rslib.

0 commit comments

Comments
 (0)