-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
55 lines (52 loc) · 1.32 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import typescript from "@rollup/plugin-typescript";
import path from "path";
import { defineConfig } from "rollup";
import externals from "rollup-plugin-node-externals";
import pkg from "./package.json";
const SHEBANG_REGEX = /^#!.+/;
/**
*
* @returns {import("rollup").Plugin}
*/
const cliEntryPlugin = () => {
return {
name: "cli-entry",
renderChunk: (code, chunk) => {
if (chunk.name !== "cli" || SHEBANG_REGEX.test(code)) return code;
return `#!/usr/bin/env node\n${code}`;
},
};
};
export default defineConfig([
{
input: ["src/index.ts", "src/cli.ts"],
output: {
dir: "lib",
format: "cjs",
preserveModules: true,
exports: "named",
banner: "#!/usr/bin/env node",
entryFileNames: (chunk) => {
if (chunk.name === "cli") return path.basename(pkg.bin.ciphenv);
if (chunk.isEntry) return path.basename(pkg.main);
return "[name].cjs";
},
},
plugins: [externals(), typescript(), cliEntryPlugin()],
},
{
input: "src/index.ts",
output: [
{
dir: "lib",
format: "esm",
preserveModules: true,
entryFileNames: (chunk) => {
if (chunk.isEntry) return path.basename(pkg.module);
return "[name].js";
},
},
],
plugins: [externals(), typescript()],
},
]);