-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
72 lines (62 loc) · 1.91 KB
/
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
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
const path = require('path');
const fs = require('fs-extra');
const {rollup} = require('rollup');
const typescript = require('rollup-plugin-typescript2');
const {Extractor, ExtractorConfig} = require('@microsoft/api-extractor');
const pkg = require('./package');
const cwd = process.cwd();
const dist = path.resolve(cwd, 'dist/');
function getPlugins(tsconfigOverride = {}) {
return [
typescript({
tsconfigOverride,
include: ['src/**/*'],
cacheRoot: path.resolve(cwd, 'node_modules/.rts2_cache'),
useTsconfigDeclarationDir: true,
}),
];
}
const external = Object.keys(pkg.dependencies).concat(Object.keys(pkg.peerDependencies), 'react-dom/server');
async function build() {
console.info('Cleaning dist/');
await fs.emptyDir(dist);
console.info('Compiling a client-side bundle');
const clientBundle = await rollup({
input: './src/index.ts',
plugins: getPlugins(),
external,
});
await clientBundle.write({
file: pkg.main,
format: 'cjs',
sourcemap: true,
});
await clientBundle.write({
file: pkg.module,
format: 'es',
sourcemap: true,
});
console.info('Bundling client-side types');
const extractorConfig = ExtractorConfig.loadFileAndPrepare(path.resolve(__dirname, 'api-extractor.json'));
Extractor.invoke(extractorConfig);
console.info('Compiling a server-side bundle');
const serverBundle = await rollup({
input: './src/server.ts',
plugins: getPlugins({compilerOptions: {target: 'es2017'}}),
external,
});
await serverBundle.write({
file: './dist/priem.server.js',
format: 'cjs',
sourcemap: true,
});
await fs.remove(path.resolve(dist, 'types'));
}
(async () => {
try {
await build();
} catch (e) {
console.error(e);
process.exitCode = 1;
}
})();