@rsbuild/plugin-node-polyfill 1.4.3 → 1.4.5
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.
- package/README.md +8 -8
- package/dist/index.cjs +10 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/package.json +82 -87
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ Add plugin to your `rsbuild.config.ts`:
|
|
|
28
28
|
|
|
29
29
|
```ts
|
|
30
30
|
// rsbuild.config.ts
|
|
31
|
-
import { pluginNodePolyfill } from
|
|
31
|
+
import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill';
|
|
32
32
|
|
|
33
33
|
export default {
|
|
34
34
|
plugins: [pluginNodePolyfill()],
|
|
@@ -47,7 +47,7 @@ When you use the above global variables in your code, the corresponding polyfill
|
|
|
47
47
|
For instance, the following code would inject the `Buffer` polyfill:
|
|
48
48
|
|
|
49
49
|
```ts
|
|
50
|
-
const bufferData = Buffer.from(
|
|
50
|
+
const bufferData = Buffer.from('abc');
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
You can disable this behavior through the `globals` option of the plugin:
|
|
@@ -95,9 +95,9 @@ pluginNodePolyfill({
|
|
|
95
95
|
When the above module is referenced in code via import / require syntax, the corresponding polyfill will be injected.
|
|
96
96
|
|
|
97
97
|
```ts
|
|
98
|
-
import { Buffer } from
|
|
98
|
+
import { Buffer } from 'buffer';
|
|
99
99
|
|
|
100
|
-
const bufferData = Buffer.from(
|
|
100
|
+
const bufferData = Buffer.from('abc');
|
|
101
101
|
```
|
|
102
102
|
|
|
103
103
|
### Fallbacks
|
|
@@ -117,7 +117,7 @@ const bufferData = Buffer.from("abc");
|
|
|
117
117
|
Currently there is no polyfill for the above modules on the browser side, so when you import the above modules, it will automatically fallback to an empty object.
|
|
118
118
|
|
|
119
119
|
```ts
|
|
120
|
-
import fs from
|
|
120
|
+
import fs from 'fs';
|
|
121
121
|
|
|
122
122
|
console.log(fs); // -> {}
|
|
123
123
|
```
|
|
@@ -210,7 +210,7 @@ Specify an array of modules for which polyfills should be injected. If this opti
|
|
|
210
210
|
|
|
211
211
|
```ts
|
|
212
212
|
pluginNodePolyfill({
|
|
213
|
-
include: [
|
|
213
|
+
include: ['buffer', 'crypto'], // Only "buffer" and "crypto" modules will be polyfilled.
|
|
214
214
|
});
|
|
215
215
|
```
|
|
216
216
|
|
|
@@ -223,7 +223,7 @@ Specify an array of modules for which polyfills should not be injected from the
|
|
|
223
223
|
|
|
224
224
|
```ts
|
|
225
225
|
pluginNodePolyfill({
|
|
226
|
-
exclude: [
|
|
226
|
+
exclude: ['http', 'https'], // All modules except "http" and "https" will be polyfilled.
|
|
227
227
|
});
|
|
228
228
|
```
|
|
229
229
|
|
|
@@ -237,7 +237,7 @@ Override the default polyfills for specific modules.
|
|
|
237
237
|
```ts
|
|
238
238
|
pluginNodePolyfill({
|
|
239
239
|
overrides: {
|
|
240
|
-
fs:
|
|
240
|
+
fs: 'memfs',
|
|
241
241
|
},
|
|
242
242
|
});
|
|
243
243
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
|
|
3
|
-
return
|
|
3
|
+
return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
4
4
|
}();
|
|
5
5
|
var __webpack_require__ = {};
|
|
6
6
|
(()=>{
|
|
@@ -16,7 +16,7 @@ var __webpack_require__ = {};
|
|
|
16
16
|
})();
|
|
17
17
|
(()=>{
|
|
18
18
|
__webpack_require__.r = (exports1)=>{
|
|
19
|
-
if (
|
|
19
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
20
20
|
value: 'Module'
|
|
21
21
|
});
|
|
22
22
|
Object.defineProperty(exports1, '__esModule', {
|
|
@@ -27,13 +27,13 @@ var __webpack_require__ = {};
|
|
|
27
27
|
var __webpack_exports__ = {};
|
|
28
28
|
__webpack_require__.r(__webpack_exports__);
|
|
29
29
|
__webpack_require__.d(__webpack_exports__, {
|
|
30
|
-
getResolveFallback: ()=>getResolveFallback,
|
|
31
30
|
PLUGIN_NODE_POLYFILL_NAME: ()=>PLUGIN_NODE_POLYFILL_NAME,
|
|
31
|
+
builtinMappingResolved: ()=>builtinMappingResolved,
|
|
32
32
|
getProvideGlobals: ()=>getProvideGlobals,
|
|
33
|
+
getResolveFallback: ()=>getResolveFallback,
|
|
33
34
|
pluginNodePolyfill: ()=>pluginNodePolyfill,
|
|
34
35
|
resolvePolyfill: ()=>resolvePolyfill,
|
|
35
|
-
resolvedPolyfillToModules: ()=>resolvedPolyfillToModules
|
|
36
|
-
builtinMappingResolved: ()=>builtinMappingResolved
|
|
36
|
+
resolvedPolyfillToModules: ()=>resolvedPolyfillToModules
|
|
37
37
|
});
|
|
38
38
|
const external_node_module_namespaceObject = require("node:module");
|
|
39
39
|
const libs_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
@@ -141,7 +141,7 @@ function pluginNodePolyfill(options = {}) {
|
|
|
141
141
|
return {
|
|
142
142
|
name: PLUGIN_NODE_POLYFILL_NAME,
|
|
143
143
|
setup (api) {
|
|
144
|
-
api.modifyBundlerChain(async (chain, { isServer, rspack })=>{
|
|
144
|
+
api.modifyBundlerChain(async (chain, { isServer, bundler, rspack })=>{
|
|
145
145
|
if (isServer && !force) return;
|
|
146
146
|
chain.resolve.fallback.merge(getResolveFallback({
|
|
147
147
|
protocolImports,
|
|
@@ -150,10 +150,10 @@ function pluginNodePolyfill(options = {}) {
|
|
|
150
150
|
overrides
|
|
151
151
|
}));
|
|
152
152
|
const provideGlobals = await getProvideGlobals(options.globals, overrides);
|
|
153
|
-
if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(
|
|
153
|
+
if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(bundler.ProvidePlugin, [
|
|
154
154
|
provideGlobals
|
|
155
155
|
]);
|
|
156
|
-
if (protocolImports) {
|
|
156
|
+
if (protocolImports && 'rspack' === api.context.bundlerType) {
|
|
157
157
|
const regex = /^node:/;
|
|
158
158
|
chain.plugin('protocol-imports').use(rspack.NormalModuleReplacementPlugin, [
|
|
159
159
|
regex,
|
|
@@ -173,7 +173,7 @@ exports.getResolveFallback = __webpack_exports__.getResolveFallback;
|
|
|
173
173
|
exports.pluginNodePolyfill = __webpack_exports__.pluginNodePolyfill;
|
|
174
174
|
exports.resolvePolyfill = __webpack_exports__.resolvePolyfill;
|
|
175
175
|
exports.resolvedPolyfillToModules = __webpack_exports__.resolvedPolyfillToModules;
|
|
176
|
-
for(var
|
|
176
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
177
177
|
"PLUGIN_NODE_POLYFILL_NAME",
|
|
178
178
|
"builtinMappingResolved",
|
|
179
179
|
"getProvideGlobals",
|
|
@@ -181,7 +181,7 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
|
181
181
|
"pluginNodePolyfill",
|
|
182
182
|
"resolvePolyfill",
|
|
183
183
|
"resolvedPolyfillToModules"
|
|
184
|
-
].indexOf(
|
|
184
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
185
185
|
Object.defineProperty(exports, '__esModule', {
|
|
186
186
|
value: true
|
|
187
187
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -89,4 +89,4 @@ export declare const getResolveFallback: ({ protocolImports, exclude, include, o
|
|
|
89
89
|
export declare const getProvideGlobals: (globals?: Globals, overrides?: PluginNodePolyfillOptions["overrides"]) => Promise<Record<string, string | string[]>>;
|
|
90
90
|
export declare const PLUGIN_NODE_POLYFILL_NAME = "rsbuild:node-polyfill";
|
|
91
91
|
export declare function pluginNodePolyfill(options?: PluginNodePolyfillOptions): RsbuildPlugin;
|
|
92
|
-
export { builtinMappingResolved, resolvedPolyfillToModules
|
|
92
|
+
export { builtinMappingResolved, resolvedPolyfillToModules } from './libs.js';
|
package/dist/index.js
CHANGED
|
@@ -104,7 +104,7 @@ function pluginNodePolyfill(options = {}) {
|
|
|
104
104
|
return {
|
|
105
105
|
name: PLUGIN_NODE_POLYFILL_NAME,
|
|
106
106
|
setup (api) {
|
|
107
|
-
api.modifyBundlerChain(async (chain, { isServer, rspack })=>{
|
|
107
|
+
api.modifyBundlerChain(async (chain, { isServer, bundler, rspack })=>{
|
|
108
108
|
if (isServer && !force) return;
|
|
109
109
|
chain.resolve.fallback.merge(getResolveFallback({
|
|
110
110
|
protocolImports,
|
|
@@ -113,10 +113,10 @@ function pluginNodePolyfill(options = {}) {
|
|
|
113
113
|
overrides
|
|
114
114
|
}));
|
|
115
115
|
const provideGlobals = await getProvideGlobals(options.globals, overrides);
|
|
116
|
-
if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(
|
|
116
|
+
if (Object.keys(provideGlobals).length) chain.plugin('node-polyfill-provide').use(bundler.ProvidePlugin, [
|
|
117
117
|
provideGlobals
|
|
118
118
|
]);
|
|
119
|
-
if (protocolImports) {
|
|
119
|
+
if (protocolImports && 'rspack' === api.context.bundlerType) {
|
|
120
120
|
const regex = /^node:/;
|
|
121
121
|
chain.plugin('protocol-imports').use(rspack.NormalModuleReplacementPlugin, [
|
|
122
122
|
regex,
|
package/package.json
CHANGED
|
@@ -1,88 +1,83 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"publishConfig": {
|
|
85
|
-
"access": "public",
|
|
86
|
-
"registry": "https://registry.npmjs.org/"
|
|
87
|
-
}
|
|
88
|
-
}
|
|
2
|
+
"name": "@rsbuild/plugin-node-polyfill",
|
|
3
|
+
"version": "1.4.5",
|
|
4
|
+
"repository": "https://github.com/rstackjs/rsbuild-plugin-node-polyfill",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/index.cjs",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"simple-git-hooks": {
|
|
21
|
+
"pre-commit": "pnpm run lint:write"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"assert": "^2.1.0",
|
|
25
|
+
"browserify-zlib": "^0.2.0",
|
|
26
|
+
"buffer": "^5.7.1",
|
|
27
|
+
"console-browserify": "^1.2.0",
|
|
28
|
+
"constants-browserify": "^1.0.0",
|
|
29
|
+
"crypto-browserify": "^3.12.1",
|
|
30
|
+
"domain-browser": "^5.7.0",
|
|
31
|
+
"events": "^3.3.0",
|
|
32
|
+
"https-browserify": "^1.0.0",
|
|
33
|
+
"os-browserify": "^0.3.0",
|
|
34
|
+
"path-browserify": "^1.0.1",
|
|
35
|
+
"process": "^0.11.10",
|
|
36
|
+
"punycode": "^2.3.1",
|
|
37
|
+
"querystring-es3": "^0.2.1",
|
|
38
|
+
"readable-stream": "^4.7.0",
|
|
39
|
+
"stream-browserify": "^3.0.0",
|
|
40
|
+
"stream-http": "^3.2.0",
|
|
41
|
+
"string_decoder": "^1.3.0",
|
|
42
|
+
"timers-browserify": "^2.0.12",
|
|
43
|
+
"tty-browserify": "^0.0.1",
|
|
44
|
+
"url": "^0.11.4",
|
|
45
|
+
"util": "^0.12.5",
|
|
46
|
+
"vm-browserify": "^1.1.2"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@playwright/test": "^1.60.0",
|
|
50
|
+
"@rsbuild/core": "^2.0.7",
|
|
51
|
+
"@rslib/core": "^0.21.5",
|
|
52
|
+
"@rslint/core": "^0.5.3",
|
|
53
|
+
"@rstest/core": "0.10.2",
|
|
54
|
+
"@types/node": "^24.12.4",
|
|
55
|
+
"playwright": "^1.60.0",
|
|
56
|
+
"prettier": "^3.8.3",
|
|
57
|
+
"simple-git-hooks": "^2.13.1",
|
|
58
|
+
"tsx": "^4.22.3",
|
|
59
|
+
"typescript": "6.0.3"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@rsbuild/core": "^1.0.0 || ^2.0.0-0"
|
|
63
|
+
},
|
|
64
|
+
"peerDependenciesMeta": {
|
|
65
|
+
"@rsbuild/core": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"publishConfig": {
|
|
70
|
+
"access": "public",
|
|
71
|
+
"registry": "https://registry.npmjs.org/"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "rslib",
|
|
75
|
+
"dev": "rslib -w",
|
|
76
|
+
"lint": "rslint && prettier -c .",
|
|
77
|
+
"lint:write": "rslint --fix && prettier -w .",
|
|
78
|
+
"test": "pnpm run /^test:/",
|
|
79
|
+
"test:e2e": "playwright test",
|
|
80
|
+
"test:unit": "rstest",
|
|
81
|
+
"bump": "npx bumpp"
|
|
82
|
+
}
|
|
83
|
+
}
|