@rsbuild/plugin-node-polyfill 1.4.4 → 1.4.6
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 +12 -8
- package/dist/index.d.ts +1 -1
- 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
|
@@ -4,11 +4,15 @@ const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
|
|
|
4
4
|
}();
|
|
5
5
|
var __webpack_require__ = {};
|
|
6
6
|
(()=>{
|
|
7
|
-
__webpack_require__.d = (exports1,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
8
|
+
var define = (defs, kind)=>{
|
|
9
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
[kind]: defs[key]
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
define(getters, "get");
|
|
15
|
+
define(values, "value");
|
|
12
16
|
};
|
|
13
17
|
})();
|
|
14
18
|
(()=>{
|
|
@@ -27,13 +31,13 @@ var __webpack_require__ = {};
|
|
|
27
31
|
var __webpack_exports__ = {};
|
|
28
32
|
__webpack_require__.r(__webpack_exports__);
|
|
29
33
|
__webpack_require__.d(__webpack_exports__, {
|
|
30
|
-
getResolveFallback: ()=>getResolveFallback,
|
|
31
34
|
PLUGIN_NODE_POLYFILL_NAME: ()=>PLUGIN_NODE_POLYFILL_NAME,
|
|
35
|
+
builtinMappingResolved: ()=>builtinMappingResolved,
|
|
32
36
|
getProvideGlobals: ()=>getProvideGlobals,
|
|
37
|
+
getResolveFallback: ()=>getResolveFallback,
|
|
33
38
|
pluginNodePolyfill: ()=>pluginNodePolyfill,
|
|
34
39
|
resolvePolyfill: ()=>resolvePolyfill,
|
|
35
|
-
resolvedPolyfillToModules: ()=>resolvedPolyfillToModules
|
|
36
|
-
builtinMappingResolved: ()=>builtinMappingResolved
|
|
40
|
+
resolvedPolyfillToModules: ()=>resolvedPolyfillToModules
|
|
37
41
|
});
|
|
38
42
|
const external_node_module_namespaceObject = require("node:module");
|
|
39
43
|
const libs_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
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/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.6",
|
|
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.9",
|
|
51
|
+
"@rslib/core": "^0.22.0",
|
|
52
|
+
"@rslint/core": "^0.5.3",
|
|
53
|
+
"@rstest/core": "0.10.3",
|
|
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"
|
|
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
|
+
}
|