cowrite / scripts /build.js
lvwerra's picture
lvwerra HF Staff
Upload folder using huggingface_hub
704a62b verified
Raw
History Blame Contribute Delete
992 Bytes
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)