@rsbuild/plugin-node-polyfill 0.0.17 → 0.0.18
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 +5 -2
- package/dist/index.js +8 -6
- package/dist/index.mjs +51 -0
- package/package.json +5 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RsbuildPlugin, RsbuildPluginAPI } from '@rsbuild/core';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Usage:
|
|
4
5
|
*
|
|
@@ -6,4 +7,6 @@ import type { RsbuildPlugin, RsbuildPluginAPI } from '@rsbuild/core';
|
|
|
6
7
|
*
|
|
7
8
|
* rsbuild.addPlugins([ pluginNodePolyfill() ]);
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
+
declare function pluginNodePolyfill(): RsbuildPlugin<RsbuildPluginAPI>;
|
|
11
|
+
|
|
12
|
+
export { pluginNodePolyfill };
|
package/dist/index.js
CHANGED
|
@@ -26,12 +26,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
29
31
|
var src_exports = {};
|
|
30
32
|
__export(src_exports, {
|
|
31
33
|
pluginNodePolyfill: () => pluginNodePolyfill
|
|
32
34
|
});
|
|
33
35
|
module.exports = __toCommonJS(src_exports);
|
|
34
|
-
|
|
36
|
+
var getResolveFallback = (nodeLibs) => Object.keys(nodeLibs).reduce(
|
|
35
37
|
(previous, name) => {
|
|
36
38
|
if (nodeLibs[name]) {
|
|
37
39
|
previous[name] = nodeLibs[name];
|
|
@@ -42,11 +44,11 @@ const getResolveFallback = (nodeLibs) => Object.keys(nodeLibs).reduce(
|
|
|
42
44
|
},
|
|
43
45
|
{}
|
|
44
46
|
);
|
|
45
|
-
|
|
46
|
-
const { default: nodeLibs } = await
|
|
47
|
+
var getProvideLibs = async () => {
|
|
48
|
+
const { default: nodeLibs } = await import(
|
|
47
49
|
// @ts-expect-error
|
|
48
50
|
"node-libs-browser"
|
|
49
|
-
)
|
|
51
|
+
);
|
|
50
52
|
return {
|
|
51
53
|
Buffer: [nodeLibs.buffer, "Buffer"],
|
|
52
54
|
process: [nodeLibs.process]
|
|
@@ -60,10 +62,10 @@ function pluginNodePolyfill() {
|
|
|
60
62
|
if (isServer) {
|
|
61
63
|
return;
|
|
62
64
|
}
|
|
63
|
-
const { default: nodeLibs } = await
|
|
65
|
+
const { default: nodeLibs } = await import(
|
|
64
66
|
// @ts-expect-error
|
|
65
67
|
"node-libs-browser"
|
|
66
|
-
)
|
|
68
|
+
);
|
|
67
69
|
chain.resolve.fallback.merge(getResolveFallback(nodeLibs));
|
|
68
70
|
chain.plugin(CHAIN_ID.PLUGIN.NODE_POLYFILL_PROVIDE).use(bundler.ProvidePlugin, [await getProvideLibs()]);
|
|
69
71
|
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.39.2_typescript@5.2.2/node_modules/@modern-js/module-tools/shims/esm.js
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
// ../../scripts/require_shims.js
|
|
6
|
+
import { createRequire } from "module";
|
|
7
|
+
global.require = createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// src/index.ts
|
|
10
|
+
var getResolveFallback = (nodeLibs) => Object.keys(nodeLibs).reduce(
|
|
11
|
+
(previous, name) => {
|
|
12
|
+
if (nodeLibs[name]) {
|
|
13
|
+
previous[name] = nodeLibs[name];
|
|
14
|
+
} else {
|
|
15
|
+
previous[name] = false;
|
|
16
|
+
}
|
|
17
|
+
return previous;
|
|
18
|
+
},
|
|
19
|
+
{}
|
|
20
|
+
);
|
|
21
|
+
var getProvideLibs = async () => {
|
|
22
|
+
const { default: nodeLibs } = await import(
|
|
23
|
+
// @ts-expect-error
|
|
24
|
+
"node-libs-browser"
|
|
25
|
+
);
|
|
26
|
+
return {
|
|
27
|
+
Buffer: [nodeLibs.buffer, "Buffer"],
|
|
28
|
+
process: [nodeLibs.process]
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
function pluginNodePolyfill() {
|
|
32
|
+
return {
|
|
33
|
+
name: "plugin-node-polyfill",
|
|
34
|
+
setup(api) {
|
|
35
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, bundler }) => {
|
|
36
|
+
if (isServer) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const { default: nodeLibs } = await import(
|
|
40
|
+
// @ts-expect-error
|
|
41
|
+
"node-libs-browser"
|
|
42
|
+
);
|
|
43
|
+
chain.resolve.fallback.merge(getResolveFallback(nodeLibs));
|
|
44
|
+
chain.plugin(CHAIN_ID.PLUGIN.NODE_POLYFILL_PROVIDE).use(bundler.ProvidePlugin, [await getProvideLibs()]);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
pluginNodePolyfill
|
|
51
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-node-polyfill",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "Node polyfill plugin for Rsbuild",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"repository": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
15
16
|
"default": "./dist/index.js"
|
|
16
17
|
}
|
|
17
18
|
},
|
|
@@ -22,12 +23,12 @@
|
|
|
22
23
|
],
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"node-libs-browser": "2.2.1",
|
|
25
|
-
"@rsbuild/shared": "0.0.
|
|
26
|
+
"@rsbuild/shared": "0.0.18"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"typescript": "^5.2.2",
|
|
29
|
-
"@rsbuild/core": "0.0.
|
|
30
|
-
"@rsbuild/webpack": "0.0.
|
|
30
|
+
"@rsbuild/core": "0.0.18",
|
|
31
|
+
"@rsbuild/webpack": "0.0.18"
|
|
31
32
|
},
|
|
32
33
|
"publishConfig": {
|
|
33
34
|
"access": "public",
|