-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.js
46 lines (41 loc) · 1.35 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
import path from 'path';
import { Glob } from 'bun';
import esbuild from 'esbuild';
import { execSync } from 'child_process';
async function build(packageDir) {
const input = `${packageDir}/src/index.ts`;
const outDir = `${packageDir}/dist`;
const tsconfig = `${packageDir}/tsconfig.json`;
// ----- Generate type declaration files ----- //
try {
execSync(`tsc --emitDeclarationOnly --declaration --outDir ${outDir} --project ${tsconfig} --pretty`, {
stdio: 'inherit',
});
console.log(`Built ${outDir}/index.d.ts`);
} catch (error) {
// Process will exit with error code due to execSync failure
console.error('Could not build type declaration files');
process.exit(1);
}
// ----- Build the package ----- //
// esbuild configuration
await esbuild.build({
entryPoints: [input],
outdir: outDir,
bundle: true,
banner: {
js: '/***** Paper Shaders: https://github.com/paper-design/shaders *****/',
},
platform: 'browser',
target: 'es2022',
format: 'esm',
treeShaking: true,
sourcemap: true,
minify: true,
external: ['react'],
packages: 'external', // Treat workspace dependencies as external (the publish script will replace workspace:* with the actual version)
});
console.log(`Built ${outDir}/index.js`);
}
build('packages/shaders');
build('packages/shaders-react');