-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
86 lines (81 loc) · 2.01 KB
/
rollup.config.mjs
File metadata and controls
86 lines (81 loc) · 2.01 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
import typescript from "@rollup/plugin-typescript";
import { readFileSync, writeFileSync } from "fs";
import { join } from "path";
const pkg = JSON.parse(readFileSync("./package.json", "utf8"));
// Get all external dependencies
const externalPackages = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
"node:crypto",
"node:util",
"fs",
"path",
];
// Function to handle subpath imports (e.g., @noble/curves/secp256k1)
const external = (id) => {
return externalPackages.some((pkg) => id === pkg || id.startsWith(pkg + "/"));
};
// Plugin to create package.json files in dist directories
const createPackageJson = (type) => ({
name: "create-package-json",
writeBundle(options) {
const content = JSON.stringify({ type }, null, 2);
writeFileSync(join(options.dir, "package.json"), content);
},
});
export default [
// ESM build
{
input: "index.ts",
external,
output: {
dir: "dist/esm",
format: "es",
preserveModules: true,
preserveModulesRoot: ".",
sourcemap: true,
},
plugins: [
typescript({
tsconfig: "./tsconfig.json",
declaration: true,
declarationMap: true,
outDir: "dist/esm",
compilerOptions: {
module: "ESNext",
target: "ES2022",
},
exclude: ["**/*.test.ts", "**/*.spec.ts"],
}),
createPackageJson("module"),
],
},
// CJS build
{
input: "index.ts",
external,
output: {
dir: "dist/cjs",
format: "cjs",
preserveModules: true,
preserveModulesRoot: ".",
sourcemap: true,
exports: "named",
interop: "auto",
},
plugins: [
typescript({
tsconfig: "./tsconfig.json",
declaration: true,
declarationMap: true,
outDir: "dist/cjs",
compilerOptions: {
module: "ESNext",
target: "ES2022",
},
exclude: ["**/*.test.ts", "**/*.spec.ts"],
}),
createPackageJson("commonjs"),
],
},
];