-
Notifications
You must be signed in to change notification settings - Fork 115
/
build.js
82 lines (76 loc) · 2.25 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
73
74
75
76
77
78
79
80
81
82
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable import/no-extraneous-dependencies */
const cp = require('child_process');
const esbuild = require('esbuild');
const { nodeExternalsPlugin } = require('esbuild-node-externals');
const svgrPlugin = require('esbuild-plugin-svgr');
const { sassPlugin } = require('esbuild-sass-plugin');
const packagejson = require('./package.json');
const spawn = (command, args) => {
const childProcess = cp.spawn(command, args, {
shell: true,
stdio: 'inherit'
});
return new Promise((resolve, reject) => {
childProcess.once('exit', (code) => {
if (code !== 0) {
return reject();
}
return resolve();
});
childProcess.once('error', (err) => reject(err));
});
};
const WATCH = !!process.env.WATCH;
const esbuildConf = (format) => ({
entryPoints: [
'src/index.ts',
'src/theme/index.ts',
'src/components/Divider/index.ts',
'src/components/Tabs/index.ts',
'src/components/Tooltip/index.ts',
'src/components/Typography/index.ts',
'src/components/Toggle/index.ts',
'src/components/InputField/index.ts',
'src/components/Button/index.ts',
'src/components/Icons/index.ts',
'src/components/CodeInput/index.ts',
'src/components/CircularProgress/index.ts'
],
splitting: format === 'esm',
bundle: true,
platform: 'node',
format: format,
outdir: `dist/${format}`,
sourcemap: true,
sourcesContent: false,
treeShaking: true,
minify: true,
plugins: [nodeExternalsPlugin(), svgrPlugin(), sassPlugin()],
watch: !!process.env.WATCH && {
onRebuild(error) {
if (error) {
console.error(`Error while rebuilding ${format} for ${packagejson.name}:`, error);
} else {
console.log(`Rebuilt ${format} for ${packagejson.name}`);
}
}
},
incremental: true
});
if (WATCH) {
console.log(`Starting watch mode for ${packagejson.name}`);
}
Promise.all([
esbuild.build(esbuildConf('cjs')),
esbuild.build(esbuildConf('esm')),
WATCH ? spawn('yarn tsc -b --preserveWatchOutput -w') : spawn('yarn tsc -b')
])
.then(() => {
console.log(`Built ${packagejson.name}`);
process.exit(0);
})
.catch((e) => {
console.error(`Build for ${packagejson.name} failed:`, e);
process.exit(1);
});