-
Notifications
You must be signed in to change notification settings - Fork 34
/
post-build.js
36 lines (33 loc) · 1.07 KB
/
post-build.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
import path from 'path';
import {fileURLToPath} from 'url';
import {rollup} from 'rollup';
import {babel} from '@rollup/plugin-babel';
(async () => {
const project = path.join(fileURLToPath(import.meta.url), '..', '..');
const config = {
input: path.join(project, 'src', 'internal.ts'),
external: id => {
if (id.startsWith('.')) {
return false;
}
return path.relative(path.join(project, 'src'), id).startsWith('..');
},
plugins: [
{
transform(code, id) {
if (id.endsWith('.ts')) {
return code.replace(/\.js';/g, '.ts\';');
}
},
},
babel({plugins: ['@babel/plugin-transform-typescript'], extensions: ['.ts'], babelHelpers: 'bundled'}),
],
};
const bundle = await rollup(config);
const outuput = {
file: path.join(project, 'dist', 'internal.cjs'),
format: 'cjs',
exports: 'named',
};
await bundle.write(outuput);
})();