-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
rollup.config.js
41 lines (38 loc) · 1.08 KB
/
rollup.config.js
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
import { builtinModules } from "node:module";
import typescript from "@rollup/plugin-typescript";
import resolve from "@rollup/plugin-node-resolve";
import alias from "@rollup/plugin-alias";
import pkg from "./package.json" assert { type: "json" };
const EXTENSIONS = [".js", ".ts"];
const ENV = process.env.ENV ? process.env.ENV : "node";
const FMT = process.env.FMT ? process.env.FMT : "esm";
const plugins = [
typescript({
tsconfig: "tsconfig.json"
}),
resolve({ extensions: EXTENSIONS })
];
if (ENV !== "node") {
plugins.unshift(
alias({
entries: [{ find: "node:crypto", replacement: "./stub.js" }]
})
);
}
const extension = FMT === "cjs" ? "cjs" : "js";
const externals =
FMT === "esm"
? [...builtinModules, ...(pkg.dependencies ? Object.keys(pkg.dependencies) : [])]
: [...builtinModules];
export default {
external: externals,
input: "source/index.ts",
output: [
{
dir: `dist/${ENV}`,
format: FMT,
entryFileNames: `[name].${extension}`
}
],
plugins
};