-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.ts
85 lines (78 loc) · 1.76 KB
/
rollup.config.ts
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
import fs from 'fs';
import path from 'path';
import { defineConfig } from 'rollup';
import { dts } from 'rollup-plugin-dts';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import replace from '@rollup/plugin-replace';
function deleteDist() {
return {
buildStart() {
if (!fs.existsSync('dist')) return;
fs.readdir('dist', (err, files) => {
if (err) {
console.error(err);
return;
}
files.forEach((file) => {
const filePath = path.join('dist', file);
fs.stat(filePath, (err, stats) => {
if (err) {
console.error(`Unable to retrieve file status: ${err}`);
return;
}
if (!stats.isFile()) return;
fs.unlink(filePath, err => {
if (err) {
console.error(`Unable to delete file: ${err}`);
return;
}
});
});
})
})
},
};
}
const plugins = [
deleteDist(),
typescript(),
commonjs(),
resolve(),
json(),
replace({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),
];
if (process.env.NODE_ENV === 'production') {
plugins.push(terser({
keep_classnames: true,
keep_fnames: true,
}));
}
export default defineConfig([
{
input: 'src/index.ts',
output: [
{
format: 'cjs',
dir: 'dist',
name: 'index',
},
],
plugins,
},
{
input: 'src/index.ts',
output: [
{
format: 'cjs',
file: 'dist/index.d.ts',
},
],
plugins: [dts()],
}
]);