@rsbuild/plugin-node-polyfill 0.3.7 → 0.3.8
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/dist/index.d.ts +17 -2
- package/dist/index.js +14 -7
- package/dist/index.mjs +14 -7
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { RsbuildPlugin } from '@rsbuild/core';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type Globals = {
|
|
4
|
+
process?: boolean;
|
|
5
|
+
Buffer?: boolean;
|
|
6
|
+
};
|
|
7
|
+
type PluginNodePolyfillOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* Whether to provide polyfill of globals.
|
|
10
|
+
* @default
|
|
11
|
+
* {
|
|
12
|
+
* Buffer: true,
|
|
13
|
+
* process: true,
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
globals?: Globals;
|
|
17
|
+
};
|
|
18
|
+
declare function pluginNodePolyfill(options?: PluginNodePolyfillOptions): RsbuildPlugin;
|
|
4
19
|
|
|
5
|
-
export { pluginNodePolyfill };
|
|
20
|
+
export { type PluginNodePolyfillOptions, pluginNodePolyfill };
|
package/dist/index.js
CHANGED
|
@@ -127,13 +127,17 @@ var getResolveFallback = (nodeLibs) => Object.keys(nodeLibs).reduce(
|
|
|
127
127
|
},
|
|
128
128
|
{}
|
|
129
129
|
);
|
|
130
|
-
var
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
130
|
+
var getProvideGlobals = async (globals) => {
|
|
131
|
+
const result = {};
|
|
132
|
+
if (globals?.Buffer !== false) {
|
|
133
|
+
result.Buffer = [buffer, "Buffer"];
|
|
134
|
+
}
|
|
135
|
+
if (globals?.process !== false) {
|
|
136
|
+
result.process = [process];
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
135
139
|
};
|
|
136
|
-
function pluginNodePolyfill() {
|
|
140
|
+
function pluginNodePolyfill(options = {}) {
|
|
137
141
|
return {
|
|
138
142
|
name: "rsbuild:node-polyfill",
|
|
139
143
|
setup(api) {
|
|
@@ -142,7 +146,10 @@ function pluginNodePolyfill() {
|
|
|
142
146
|
return;
|
|
143
147
|
}
|
|
144
148
|
chain.resolve.fallback.merge(getResolveFallback(libs_exports));
|
|
145
|
-
|
|
149
|
+
const provideGlobals = await getProvideGlobals(options.globals);
|
|
150
|
+
if (Object.keys(provideGlobals).length) {
|
|
151
|
+
chain.plugin(CHAIN_ID.PLUGIN.NODE_POLYFILL_PROVIDE).use(bundler.ProvidePlugin, [provideGlobals]);
|
|
152
|
+
}
|
|
146
153
|
});
|
|
147
154
|
}
|
|
148
155
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -121,13 +121,17 @@ var getResolveFallback = (nodeLibs) => Object.keys(nodeLibs).reduce(
|
|
|
121
121
|
},
|
|
122
122
|
{}
|
|
123
123
|
);
|
|
124
|
-
var
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
124
|
+
var getProvideGlobals = async (globals) => {
|
|
125
|
+
const result = {};
|
|
126
|
+
if (globals?.Buffer !== false) {
|
|
127
|
+
result.Buffer = [buffer, "Buffer"];
|
|
128
|
+
}
|
|
129
|
+
if (globals?.process !== false) {
|
|
130
|
+
result.process = [process];
|
|
131
|
+
}
|
|
132
|
+
return result;
|
|
129
133
|
};
|
|
130
|
-
function pluginNodePolyfill() {
|
|
134
|
+
function pluginNodePolyfill(options = {}) {
|
|
131
135
|
return {
|
|
132
136
|
name: "rsbuild:node-polyfill",
|
|
133
137
|
setup(api) {
|
|
@@ -136,7 +140,10 @@ function pluginNodePolyfill() {
|
|
|
136
140
|
return;
|
|
137
141
|
}
|
|
138
142
|
chain.resolve.fallback.merge(getResolveFallback(libs_exports));
|
|
139
|
-
|
|
143
|
+
const provideGlobals = await getProvideGlobals(options.globals);
|
|
144
|
+
if (Object.keys(provideGlobals).length) {
|
|
145
|
+
chain.plugin(CHAIN_ID.PLUGIN.NODE_POLYFILL_PROVIDE).use(bundler.ProvidePlugin, [provideGlobals]);
|
|
146
|
+
}
|
|
140
147
|
});
|
|
141
148
|
}
|
|
142
149
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-node-polyfill",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"description": "Node polyfill plugin for Rsbuild",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"repository": {
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
"url": "^0.11.3",
|
|
47
47
|
"util": "^0.12.5",
|
|
48
48
|
"vm-browserify": "^1.1.2",
|
|
49
|
-
"@rsbuild/shared": "0.3.
|
|
49
|
+
"@rsbuild/shared": "0.3.8"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"typescript": "^5.3.0",
|
|
53
|
-
"@rsbuild/core": "0.3.
|
|
53
|
+
"@rsbuild/core": "0.3.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@rsbuild/core": "^0.3.
|
|
56
|
+
"@rsbuild/core": "^0.3.8"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public",
|