-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
121 lines (114 loc) · 2.7 KB
/
rollup.config.js
File metadata and controls
121 lines (114 loc) · 2.7 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import terser from "@rollup/plugin-terser";
const input = "src/index.js";
const external = ["node:fs", "node:path", "node:zlib", "node:crypto", "node:os", "node:http"];
/**
* Replaces node:* built-in imports with empty stubs for browser builds.
* Code that actually uses these (FsAdapter, MCP HTTP transport) is never
* reached in browser environments, so the stubs are safe.
*/
function nodeBrowserStubs() {
return {
name: "node-browser-stubs",
resolveId(id) {
if (id.startsWith("node:")) return `\0node-stub:${id}`;
},
load(id) {
if (id.startsWith("\0node-stub:")) return "export default {};\n";
},
};
}
const plugins = [
resolve({ preferBuiltins: true }),
commonjs(),
];
const minPlugins = [
...plugins,
terser(),
];
const treeshake = { moduleSideEffects: false };
export default [
// ESM build (Node.js / Deno / Bun)
{
input,
treeshake,
output: {
file: "dist/skalex.esm.js",
format: "es",
sourcemap: true,
},
external,
plugins,
},
// ESM browser build - node:* built-ins stubbed out
{
input,
treeshake,
output: {
file: "dist/skalex.browser.js",
format: "es",
sourcemap: true,
inlineDynamicImports: true,
},
plugins: [nodeBrowserStubs(), ...plugins],
},
// ESM minified
{
input,
treeshake,
output: {
file: "dist/skalex.esm.min.js",
format: "es",
sourcemap: true,
},
external,
plugins: minPlugins,
},
// UMD/IIFE minified
{
input,
treeshake,
output: {
file: "dist/skalex.umd.min.js",
format: "iife",
name: "Skalex",
sourcemap: true,
inlineDynamicImports: true,
exports: "named",
// Unwrap so window.Skalex is the constructor, not { default, ... }
footer: "Skalex=Skalex.default;",
},
plugins: [nodeBrowserStubs(), ...minPlugins],
},
// CJS build
{
input,
treeshake,
output: {
file: "dist/skalex.cjs",
format: "cjs",
sourcemap: true,
exports: "named",
// Unwrap so require("skalex") returns the constructor directly,
// while require("skalex").SkalexError etc. still work.
footer: "module.exports=Object.assign(exports.default,exports);delete module.exports.default;",
},
external,
plugins,
},
// CJS minified
{
input,
treeshake,
output: {
file: "dist/skalex.min.cjs",
format: "cjs",
sourcemap: true,
exports: "named",
footer: "module.exports=Object.assign(exports.default,exports);delete module.exports.default;",
},
external,
plugins: minPlugins,
},
];