File size: 992 Bytes
99a44ac
 
 
 
 
 
 
 
 
 
704a62b
 
 
 
99a44ac
 
 
 
 
 
704a62b
99a44ac
 
 
 
 
 
704a62b
 
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
import esbuild from 'esbuild'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..')
const pub = path.join(root, 'public')

fs.mkdirSync(pub, { recursive: true })

// version stamp: the server rejects websocket clients from other builds so a
// stale tab can never silently corrupt a doc with its old state
const buildId = String(Date.now())

await esbuild.build({
  entryPoints: [path.join(root, 'client/src/doc.js'), path.join(root, 'client/src/home.js')],
  bundle: true,
  minify: true,
  format: 'iife',
  outdir: pub,
  define: { 'process.env.NODE_ENV': '"production"', __BUILD_ID__: JSON.stringify(buildId) },
  logLevel: 'info',
})

for (const f of ['doc.html', 'index.html', 'app.css']) {
  fs.copyFileSync(path.join(root, 'client', f), path.join(pub, f))
}
fs.writeFileSync(path.join(pub, 'build-id'), buildId)
console.log('build done ->', pub, 'build-id', buildId)