-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.js
49 lines (45 loc) · 1.44 KB
/
bundle.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
const estrella = require('estrella');
const base = {
entry: 'src/index.ts',
bundle: true,
sourcemap: true,
};
estrella.build({
...base,
outfile: 'dist/browser/bundle.js',
format: 'iife',
tsconfig: 'tsconfig.browser.json',
onEnd(config) {
const dtsFilesOutdir = estrella.dirname(config.outfile);
generateTypeDefs(estrella.tsconfig(config), config.entry, dtsFilesOutdir);
},
});
estrella.build({
...base,
outfile: 'dist/node/index.js',
format: 'cjs',
tsconfig: 'tsconfig.node.json',
onEnd(config) {
const dtsFilesOutdir = estrella.dirname(config.outfile);
generateTypeDefs(estrella.tsconfig(config), config.entry, dtsFilesOutdir);
},
});
function generateTypeDefs(tsconfig, entryfiles, outdir) {
const filenames = Array.from(
new Set((Array.isArray(entryfiles) ? entryfiles : [entryfiles]).concat(estrella.tsconfig.include || []))
).filter((v) => v);
estrella.log.info('Generating type declaration files for', filenames.join(', '));
const compilerOptions = {
...estrella.tsconfig.compilerOptions,
moduleResolution: undefined,
declaration: true,
outDir: outdir,
};
const program = estrella.ts.ts.createProgram(filenames, compilerOptions);
const targetSourceFile = undefined;
const writeFile = undefined;
const cancellationToken = undefined;
const emitOnlyDtsFiles = true;
program.emit(targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles);
estrella.log.info('Wrote', estrella.glob(outdir + '/*.d.ts').join(', '));
}