build js in prod
This commit is contained in:
parent
e6c9751f7d
commit
91c6ee3675
|
|
@ -8,9 +8,7 @@
|
||||||
"toes": "src/cli/index.ts"
|
"toes": "src/cli/index.ts"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "bun run src/server/index.tsx",
|
"build": "./scripts/build.sh",
|
||||||
"dev": "bun run --hot src/server/index.tsx",
|
|
||||||
"test": "bun test",
|
|
||||||
"cli:build": "bun run scripts/build.ts",
|
"cli:build": "bun run scripts/build.ts",
|
||||||
"cli:build:all": "bun run scripts/build.ts --all",
|
"cli:build:all": "bun run scripts/build.ts --all",
|
||||||
"cli:install": "bun cli:build && sudo cp dist/toes /usr/local/bin",
|
"cli:install": "bun cli:build && sudo cp dist/toes /usr/local/bin",
|
||||||
|
|
|
||||||
17
scripts/build.sh
Executable file
17
scripts/build.sh
Executable file
|
|
@ -0,0 +1,17 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
echo ">> Building client bundle"
|
||||||
|
|
||||||
|
# Clean pub directory
|
||||||
|
rm -rf pub/client
|
||||||
|
mkdir -p pub/client
|
||||||
|
|
||||||
|
# Bundle client code
|
||||||
|
bun build src/client/index.tsx \
|
||||||
|
--outfile pub/client/index.js \
|
||||||
|
--target browser \
|
||||||
|
--minify
|
||||||
|
|
||||||
|
echo ">> Client bundle created at pub/client/index.js"
|
||||||
|
ls -lh pub/client/index.js
|
||||||
|
|
@ -5,18 +5,6 @@ import { Hype } from '@because/hype'
|
||||||
|
|
||||||
const app = new Hype({ layout: false })
|
const app = new Hype({ layout: false })
|
||||||
|
|
||||||
// Serve pre-bundled client in production
|
|
||||||
if (process.env.NODE_ENV === 'production') {
|
|
||||||
app.get('/client/index.js', async (c) => {
|
|
||||||
const file = Bun.file('./dist/client/index.js')
|
|
||||||
if (!(await file.exists())) {
|
|
||||||
console.error('⚠️ Bundled client not found. Run `bun run build` first.')
|
|
||||||
return c.text('Client bundle not found', 500)
|
|
||||||
}
|
|
||||||
return new Response(file, { headers: { 'Content-Type': 'text/javascript' } })
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
app.route('/api/apps', appsRouter)
|
app.route('/api/apps', appsRouter)
|
||||||
app.route('/api/sync', syncRouter)
|
app.route('/api/sync', syncRouter)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user