-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsup.config.ts
42 lines (38 loc) · 1.07 KB
/
tsup.config.ts
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
import { exec } from 'node:child_process';
import { defineConfig } from 'tsup';
import type { Options } from 'tsup';
export default defineConfig(({ env = {} }) => {
const DEV = env.NODE_ENV === 'development';
const PROD = env.NODE_ENV === 'production';
return {
env,
entry: ['src/app.ts'],
format: ['esm'],
watch: DEV,
clean: PROD,
minify: PROD && 'terser',
define: {
__DEV__: `${DEV}`,
__PROD__: `${PROD}`,
},
splitting: true,
publicDir: true,
platform: 'node',
target: 'esnext',
terserOptions: { format: { comments: false } },
...(DEV ? createDenoDevRun() : {}),
};
});
const createDenoDevRun = (): Options => {
let run = false;
return {
onSuccess: async () => {
if (run) return;
run = true;
const e = exec('cd dist && deno run -A --watch main.js');
e.stdout?.on('data', (x) => process.stdout.write(x.toString()));
e.stderr?.on('data', (x) => process.stderr.write(x.toString()));
e.on('exit', (code) => process.exit(typeof code === 'number' ? code : 1));
},
};
};