Skip to content

Commit

Permalink
feat: add polyfillServer option (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
DasBlackfur authored Jan 30, 2025
1 parent eb9d759 commit 9c808d1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,19 @@ pluginNodePolyfill({
})
```

### polyfillServer

Polyfill the server-side code as well.

- **Type:** `boolean`
- **Default:** `false`

```ts
pluginNodePolyfill({
polyfillServer: true,
})
```

## Exported variables

- `builtinMappingResolved`: A map of Node.js builtin modules to their resolved corresponding polyfills modules.
Expand Down
15 changes: 13 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export type PluginNodePolyfillOptions = {
* @default undefined
*/
overrides?: Record<string, string | false>;
/**
* Polyfill the server-side code as well.
* @default false
*/
polyfillServer?: boolean;
};

export const resolvePolyfill = (
Expand Down Expand Up @@ -107,15 +112,21 @@ export const PLUGIN_NODE_POLYFILL_NAME = 'rsbuild:node-polyfill';
export function pluginNodePolyfill(
options: PluginNodePolyfillOptions = {},
): RsbuildPlugin {
const { protocolImports = true, include, exclude, overrides } = options;
const {
protocolImports = true,
include,
exclude,
overrides,
polyfillServer = false,
} = options;

return {
name: PLUGIN_NODE_POLYFILL_NAME,

setup(api) {
api.modifyBundlerChain(async (chain, { isServer, bundler }) => {
// The server bundle does not require node polyfill
if (isServer) {
if (isServer && !polyfillServer) {
return;
}

Expand Down

0 comments on commit 9c808d1

Please sign in to comment.