@@ -75,14 +75,17 @@ export async function build(args: {
7575 checkNodeVersion ( )
7676 setServerGlobals ( )
7777
78- const { oneOptions } = await loadUserOneOptions ( 'build' )
78+ const { oneOptions, config : viteLoadedConfig } = await loadUserOneOptions ( 'build' )
7979 const routerRoot = getRouterRootFromOneOptions ( oneOptions )
8080
8181 // Set defaultRenderMode env var so getManifest knows the correct route types
8282 if ( oneOptions . web ?. defaultRenderMode ) {
8383 process . env . ONE_DEFAULT_RENDER_MODE = oneOptions . web . defaultRenderMode
8484 }
8585
86+ // respect vite's build.outDir config, default to 'dist'
87+ const outDir = viteLoadedConfig ?. config ?. build ?. outDir ?? 'dist'
88+
8689 const manifest = getManifest ( { routerRoot } ) !
8790
8891 const serverOutputFormat =
@@ -173,7 +176,7 @@ export async function build(args: {
173176 build : {
174177 ssr : true ,
175178 emptyOutDir : false ,
176- outDir : `dist /${ subFolder } ` ,
179+ outDir : `${ outDir } /${ subFolder } ` ,
177180 copyPublicDir : false ,
178181 minify : false ,
179182 rolldownOptions : {
@@ -269,7 +272,7 @@ export async function build(args: {
269272 const outChunks = middlewareBuildInfo . output . filter ( ( x ) => x . type === 'chunk' )
270273 const chunk = outChunks . find ( ( x ) => x . facadeModuleId === fullPath )
271274 if ( ! chunk ) throw new Error ( `internal err finding middleware` )
272- builtMiddlewares [ middleware . file ] = join ( 'dist' , 'middlewares' , chunk . fileName )
275+ builtMiddlewares [ middleware . file ] = join ( outDir , 'middlewares' , chunk . fileName )
273276 }
274277 }
275278
@@ -301,8 +304,8 @@ export async function build(args: {
301304 : `concurrency: ${ BUILD_CONCURRENCY } `
302305 console . info ( `\n 🔨 build static routes (${ modeLabel } )\n` )
303306
304- const staticDir = join ( `dist /static` )
305- const clientDir = join ( `dist /client` )
307+ const staticDir = join ( `${ outDir } /static` )
308+ const clientDir = join ( `${ outDir } /client` )
306309 await ensureDir ( staticDir )
307310
308311 if ( ! vxrnOutput . serverOutput ) {
@@ -643,7 +646,7 @@ export async function build(args: {
643646 } )
644647 }
645648
646- const serverJsPath = join ( 'dist /server' , serverFileName )
649+ const serverJsPath = join ( ` ${ outDir } /server` , serverFileName )
647650
648651 let exported
649652 try {
@@ -866,6 +869,7 @@ export async function build(args: {
866869 }
867870
868871 const buildInfoForWriting : One . BuildInfo = {
872+ outDir,
869873 oneOptions,
870874 routeToBuildInfo,
871875 pathToRoute,
@@ -882,7 +886,7 @@ export async function build(args: {
882886 useRolldown : await isRolldown ( ) ,
883887 }
884888
885- await writeJSON ( toAbsolute ( `dist /buildInfo.json` ) , buildInfoForWriting )
889+ await writeJSON ( toAbsolute ( `${ outDir } /buildInfo.json` ) , buildInfoForWriting )
886890
887891 // emit version.json for skew protection polling
888892 await FSExtra . writeFile (
@@ -951,7 +955,7 @@ export async function build(args: {
951955 buildInfoForWriting . routeToBuildInfo
952956 ) ) {
953957 if ( info . serverJsPath ) {
954- const importPath = './' + info . serverJsPath . replace ( / ^ d i s t \/ / , '' )
958+ const importPath = './' + info . serverJsPath . replace ( new RegExp ( `^ ${ outDir } /` ) , '' )
955959 pageRouteMap . push ( ` '${ routeFile } ': () => import('${ importPath } ')` )
956960 }
957961 }
@@ -971,11 +975,11 @@ export async function build(args: {
971975 // Generate lazy imports for middlewares
972976 // The key must match the contextKey used to look up the middleware (e.g., "dist/middlewares/_middleware.js")
973977 for ( const [ , builtPath ] of Object . entries ( builtMiddlewares ) ) {
974- const importPath = './' + builtPath . replace ( / ^ d i s t \/ / , '' )
978+ const importPath = './' + builtPath . replace ( new RegExp ( `^ ${ outDir } /` ) , '' )
975979 middlewareRouteMap . push ( ` '${ builtPath } ': () => import('${ importPath } ')` )
976980 }
977981
978- const workerSrcPath = join ( options . root , 'dist' , '_worker-src.js' )
982+ const workerSrcPath = join ( options . root , outDir , '_worker-src.js' )
979983 const workerCode = `// Polyfill MessageChannel for React SSR (not available in Cloudflare Workers by default)
980984if (typeof MessageChannel === 'undefined') {
981985 globalThis.MessageChannel = class MessageChannel {
@@ -1066,7 +1070,7 @@ export default {
10661070 mode : 'production' ,
10671071 logLevel : 'warn' ,
10681072 build : {
1069- outDir : 'dist' ,
1073+ outDir,
10701074 emptyOutDir : false ,
10711075 // Use SSR mode with node target for proper Node.js module resolution
10721076 ssr : workerSrcPath ,
@@ -1143,12 +1147,12 @@ export default {
11431147}
11441148`
11451149 await FSExtra . writeFile (
1146- join ( options . root , 'dist' , 'wrangler.jsonc' ) ,
1150+ join ( options . root , outDir , 'wrangler.jsonc' ) ,
11471151 wranglerConfig
11481152 )
11491153
1150- postBuildLogs . push ( `Cloudflare worker bundled at dist /worker.js` )
1151- postBuildLogs . push ( `To deploy: cd dist && wrangler deploy` )
1154+ postBuildLogs . push ( `Cloudflare worker bundled at ${ outDir } /worker.js` )
1155+ postBuildLogs . push ( `To deploy: cd ${ outDir } && wrangler deploy` )
11521156
11531157 break
11541158 }
0 commit comments