-
Notifications
You must be signed in to change notification settings - Fork 16
/
rollup.config.mjs
51 lines (48 loc) · 1.18 KB
/
rollup.config.mjs
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
import fs from 'fs';
import path from 'path';
import tsPlugin from '@rollup/plugin-typescript';
export default {
input: 'src/index.ts',
output: [
{
format: 'cjs',
file: './dist/index.js',
},
{
format: 'es',
dir: 'dist',
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames: chunk => {
return `${chunk.name === 'index' ? 'index.esm' : chunk.name}.js`;
},
},
],
plugins: [
tsPlugin({
declarationDir: './dist',
sourceMap: false,
}),
removeDist(),
],
};
function removeDist(options = {}) {
const { hook = 'buildStart', buildDir = 'dist' } = options;
return {
name: 'remove-dist',
[hook]: async () => {
const folderPath = path.join(process.cwd(), buildDir);
try {
fs.accessSync(folderPath, fs.F_OK);
fs.rmSync(folderPath, { recursive: true, force: true });
} catch (err) {
if (err.code !== 'ENOENT') throw err;
try {
fs.rmSync(folderPath, { recursive: true, force: true });
} catch (innerErr) {
console.log('An error occurred while removing the folder:', innerErr);
}
}
},
};
}