-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
45 lines (40 loc) · 1003 Bytes
/
rollup.config.js
File metadata and controls
45 lines (40 loc) · 1003 Bytes
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
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import dts from "rollup-plugin-dts";
import nodeExternals from "rollup-plugin-node-externals";
const ENTRY_FILE = "src/index.ts";
const OUTPUT_DIRS = {
cjs: "dist/cjs",
dts: "dist/types",
esm: "dist/esm",
};
const createDtsConfig = () => ({
input: ENTRY_FILE,
output: { dir: OUTPUT_DIRS.dts, format: "esm" },
plugins: [dts()],
});
const createJsConfig = (format) => ({
input: ENTRY_FILE,
output: {
dir: OUTPUT_DIRS[format],
entryFileNames: format === "esm" ? "[name].mjs" : "[name].cjs",
format,
sourcemap: true,
},
plugins: [
nodeExternals(),
typescript({
compilerOptions: { outDir: OUTPUT_DIRS[format] },
exclude: ["**/*.spec.ts", "**/*.test.ts"],
tsconfig: "tsconfig.json",
}),
terser({
format: { comments: /^!/ },
}),
],
});
export default [
createDtsConfig(),
createJsConfig("esm"),
createJsConfig("cjs"),
];