-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.mjs
73 lines (65 loc) · 1.48 KB
/
build.mjs
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
import esbuild from 'esbuild'
import { resolve } from 'path'
import { promises as fs } from 'fs'
// const glob = require('tiny-glob');
const project_dir = new URL('./', import.meta.url).pathname
const assets = [
{
from: 'node_modules/monaco-editor/min/vs',
to: 'dist/vs',
},
{
from: 'node_modules/@hotwired/turbo/dist/turbo.es2017-umd.js',
to: 'dist/turbo-umd.js',
},
]
for (const { from, to } of assets) {
try {
await fs.stat(resolve(project_dir, 'public', to))
} catch (e) {
await fs.mkdir(resolve(project_dir, 'public', to, '../'), {
recursive: true,
})
await fs.symlink(
resolve(project_dir, from),
resolve(project_dir, 'public', to),
)
}
}
const backend_config = {
bundle: false,
target: 'es2022',
platform: 'node',
format: 'esm',
entryPoints: ['src/**/*.tsx', 'src/**/*.ts'],
outdir: 'dist',
jsxFactory: 'TempstreamJSX.createElement',
}
const frontend_config = {
bundle: true,
target: 'es2022',
platform: 'node',
format: 'iife',
entryPoints: ['src/front/index.ts'],
outdir: 'public/dist',
}
const frame_config = {
bundle: true,
target: 'es2022',
platform: 'node',
format: 'iife',
entryPoints: ['src/front/frame.ts'],
outdir: 'public/dist',
}
const configs = [backend_config, frontend_config, frame_config]
if (process.argv.includes('--watch')) {
for (const config of configs) {
const ctx = await esbuild.context(config)
await ctx.watch()
}
console.log('watching...')
} else {
for (const config of configs) {
await esbuild.build(config)
}
}