@@ -8,12 +8,20 @@ import { App } from "./App.tsx";
88import tailwind from "bun-plugin-tailwind" ;
99
1010// Build the HTML and all its assets before starting the server
11+ const isProduction = process . env . NODE_ENV === "production" ;
12+
1113const build = await Bun . build ( {
1214 entrypoints : [ "./index.html" ] ,
1315 // No outdir = files are kept in memory, not written to disk
14- minify : false ,
16+ minify : isProduction ,
1517 publicPath : "/" ,
18+ sourcemap : "linked" ,
1619 plugins : [ tailwind ] ,
20+ define : {
21+ "process.env.NODE_ENV" : JSON . stringify (
22+ process . env . NODE_ENV || "development"
23+ ) ,
24+ } ,
1725} ) ;
1826
1927if ( ! build . success ) {
@@ -51,13 +59,27 @@ Bun.serve({
5159 // Check if this is a request for a built asset
5260 const asset = assets . get ( url . pathname ) ;
5361 if ( asset ) {
54- return new Response ( asset ) ;
62+ const headers = isProduction
63+ ? {
64+ // Built assets have content hashes, so they can be cached indefinitely
65+ "Cache-Control" : "public, max-age=31536000, immutable" ,
66+ }
67+ : { } ;
68+
69+ return new Response ( asset , { headers } ) ;
5570 }
5671
5772 // Check if this is a request for a static file from public/
5873 const publicFile = Bun . file ( `./public${ url . pathname } ` ) ;
5974 if ( await publicFile . exists ( ) ) {
60- return new Response ( publicFile ) ;
75+ const headers = new Headers ( ) ;
76+
77+ // Add 24h caching for static assets in production
78+ if ( isProduction ) {
79+ headers . set ( "Cache-Control" , "public, max-age=86400" ) ;
80+ }
81+
82+ return new Response ( publicFile , { headers } ) ;
6183 }
6284
6385 // Otherwise, it's a page request - render with SSR
0 commit comments