-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.bundletypes.mjs
55 lines (51 loc) · 1.32 KB
/
rollup.config.bundletypes.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
52
53
54
55
import internalDel from 'del';
import del from 'rollup-plugin-delete';
import dts from 'rollup-plugin-dts';
import * as fsSync from 'fs';
const IN_DIR = 'typings-autogen';
const OUTPUT_FILE = 'dist/index.d.ts';
let earlyDelDone = false;
// Runs sequentially before buildStart hooks:
function earlyDel(targets = [], deleteOptions = {}) {
return {
name: 'earlydel',
options: function(options) {
if (!earlyDelDone) {
earlyDelDone = true;
const paths = internalDel.sync(targets, deleteOptions);
if (deleteOptions.verbose) {
console.log(`Deleted files and folders: ${paths.length}`);
if (paths.length > 0) {
paths.forEach((path) => {
console.log(path);
});
}
}
}
return null;
},
};
}
function appendDts(filePath) {
const fileContent = fsSync.readFileSync(filePath, {encoding: 'utf8'});
return {
name: 'append-dts',
renderChunk(code) {
return `${code}\n${fileContent}`;
},
};
}
export default [{
input: `${IN_DIR}/src/index.d.ts`,
output: {
file: OUTPUT_FILE,
format: 'es',
},
plugins: [
earlyDel([OUTPUT_FILE]),
dts({compilerOptions: {}}),
// appendDts('src/resources.d.ts'),
del({hook: 'buildEnd', targets: [IN_DIR]}),
],
external: ['child_process'],
}];