-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
87 lines (85 loc) · 2.59 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
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
import {nodeResolve} from "@rollup/plugin-node-resolve";
import nodePolyfills from "rollup-plugin-polyfill-node";
import sourcemaps from "rollup-plugin-sourcemaps";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "rollup-plugin-typescript2";
import external from "@yelo/rollup-node-external";
import {preserveShebangs} from "rollup-plugin-preserve-shebangs";
import fs from "fs/promises";
import dts from "rollup-plugin-dts";
import {terser} from "rollup-plugin-terser";
import fsNoPromise from "fs";
import notify from "rollup-plugin-notify";
const PRODUCTION =
process.env.NODE_ENV === "production" || process.env.NODE_ENV === "prod";
const io = [
"ir-cli",
];
const dtsFix = () => ({
writeBundle: async () => {
if (PRODUCTION) {
await fs.rm("./dist/types-tmp", {
recursive: true,
force: true,
});
}
const path = fsNoPromise.existsSync("./dist/dist/dist/types-tmp")
? "./dist/dist/dist/types-tmp"
: "./dist/dist";
for (const item of await fs.readdir(path, {
withFileTypes: true,
})) {
if (item.isFile()) {
await fs.rename(
`${path}/${item.name}`,
`./dist/${item.name}`.replace("d.d.ts", "d.ts")
);
}
}
await fs.rm("./dist/dist", {
recursive: true,
force: true,
});
},
});
export default [
io.map((item) => ({
input: `src/${item}.ts`,
plugins: [
nodeResolve(),
nodePolyfills(),
commonjs(),
...(!PRODUCTION ? [sourcemaps()] : []),
typescript({
useTsconfigDeclarationDir: true,
clean: true,
tsconfigOverride: {
compilerOptions: {
declarationDir: "./dist/types-tmp",
sourceMap: !PRODUCTION,
},
},
}),
preserveShebangs(),
...(PRODUCTION ? [terser()] : []),
notify(),
],
external: external(),
output: [
{
file: `dist/${item}.js`,
format: "es",
sourcemap: !PRODUCTION,
globals: [],
},
],
})),
[
{
input: io.map((item) => `dist/types-tmp/${item}.d.ts`),
output: [{dir: `./dist/dist`, format: "es"}],
watch: true,
plugins: [dts(), dtsFix(), notify()],
},
],
].flat();