-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
40 lines (36 loc) · 1.01 KB
/
tsdown.config.ts
File metadata and controls
40 lines (36 loc) · 1.01 KB
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
import { exec } from 'node:child_process';
import { defineConfig } from 'tsdown';
import type { Options } from 'tsdown';
export default defineConfig(({ env = {} }) => {
const DEV = env.NODE_ENV === 'development';
const PROD = env.NODE_ENV === 'production';
return {
env,
entry: ['src/app.ts'],
format: ['esm'],
target: 'esnext',
platform: 'node',
watch: DEV,
clean: PROD,
minify: PROD,
define: {
__DEV__: `${DEV}`,
__PROD__: `${PROD}`,
},
copy: [{ from: 'public', to: 'dist' }],
...(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));
},
};
};