-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.js
42 lines (38 loc) · 1.19 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
const esbuild = require('esbuild');
// const { dtsPlugin } = require('esbuild-plugin-d.ts');
const svgrPlugin = require('esbuild-plugin-svgr');
const cssModulesPlugin = require('esbuild-css-modules-plugin');
const { dependencies } = require('./package.json');
const util = require('util');
const exec = util.promisify(require('child_process').exec);
async function build() {
// make react lib
const result = await esbuild.build({
logLevel: 'info',
entryPoints: ['src/index.tsx'],
bundle: true,
minify: true,
format: 'esm',
sourcemap: 'external',
outfile: `dist/esbuild/index.js`,
metafile: true,
// remove external libs from out file
external: Object.keys(dependencies),
plugins: [
cssModulesPlugin({
v2: true,
inject: true,
}),
svgrPlugin(),
// dtsPlugin(), // broken by typescript 5, see next code-block
],
});
console.log('metafile result', result);
// make d.ts files
// old solution with "dtsPlugin()" is not working because of entryPoints, only full mode working now
await exec('npx tsc --declaration --emitDeclarationOnly');
}
build().catch((e) => {
console.error('build error', e);
process.exit(1);
});