@@ -84,6 +84,16 @@ const MODE_ARGS = {
8484 "dev:desktop" : [ "run" , "--filter=@t3tools/desktop" , "--filter=@t3tools/web" , "dev" ] ,
8585} as const satisfies Record < string , ReadonlyArray < string > > ;
8686
87+ // `--built`: the web package rebuilds into apps/web/dist and the backend serves
88+ // it, so no Vite dev server runs.
89+ const BUILT_DEV_ARGS = [
90+ "run" ,
91+ "--filter=@t3tools/web" ,
92+ "--filter=t3" ,
93+ "--parallel" ,
94+ "dev:built" ,
95+ ] as const ;
96+
8797type DevMode = keyof typeof MODE_ARGS ;
8898/**
8999 * `role` matters because only the backend honours `--host`/`T3CODE_HOST`; the
@@ -184,6 +194,17 @@ export class DevRunnerHostNotProxiableError extends Schema.TaggedError<DevRunner
184194 }
185195}
186196
197+ export class DevRunnerBuiltNeedsShareError extends Schema . TaggedError < DevRunnerBuiltNeedsShareError > ( ) (
198+ "DevRunnerBuiltNeedsShareError" ,
199+ {
200+ mode : Schema . Literals ( [ "dev" , "dev:server" , "dev:web" , "dev:desktop" ] ) ,
201+ } ,
202+ ) {
203+ override get message ( ) : string {
204+ return `--built only works with \`dev --share\` (got ${ this . mode } ${ this . mode === "dev" ? " without --share" : "" } ): the backend serves the built client on the tailnet URL.` ;
205+ }
206+ }
207+
187208const optionalStringConfig = ( name : string ) : Config . Config < string | undefined > =>
188209 Config . String ( name ) . pipe (
189210 Config . option ,
@@ -659,6 +680,7 @@ interface DevRunnerCliInput {
659680 readonly dryRun : boolean ;
660681 readonly share : boolean ;
661682 readonly seed ?: boolean | undefined ;
683+ readonly built : boolean ;
662684 readonly runArgs : ReadonlyArray < string > ;
663685}
664686
@@ -683,6 +705,10 @@ export const runDevRunnerWithInput = Effect.fn("dev-runner.runDevRunnerWithInput
683705 return yield * new DevRunnerHostNotProxiableError ( { mode : input . mode , host : input . host } ) ;
684706 }
685707
708+ if ( input . built && ( input . mode !== "dev" || ! input . share ) ) {
709+ return yield * new DevRunnerBuiltNeedsShareError ( { mode : input . mode } ) ;
710+ }
711+
686712 const worktreePath = yield * resolveGitWorktreePath ( yield * HostProcess . WorkingDirectory ) ;
687713
688714 const { offset, source } = yield * resolveOffset ( {
@@ -743,6 +769,7 @@ export const runDevRunnerWithInput = Effect.fn("dev-runner.runDevRunnerWithInput
743769 }
744770
745771 const sharedWebPort = BASE_WEB_PORT + webOffset ;
772+ let built = false ;
746773 if ( input . share ) {
747774 if ( input . mode === "dev:server" ) {
748775 yield * Effect . logInfo ( "[dev-runner] --share has no effect for dev:server (no web server)." ) ;
@@ -755,18 +782,32 @@ export const runDevRunnerWithInput = Effect.fn("dev-runner.runDevRunnerWithInput
755782 // process (and reboots), so the cleanup has to be registered atomically
756783 // with creating it. An interrupt landing in between would otherwise
757784 // leave a mapping pointing at a port nothing is listening on.
758- const shared = yield * Effect . acquireRelease ( shareDevServer ( { webPort : sharedWebPort } ) , ( ) =>
759- unshareDevServer ( sharedWebPort ) . pipe (
760- Effect . flatMap ( ( result ) =>
761- result . cleared
762- ? Effect . void
763- : Effect . logWarning (
764- `[dev-runner] could not remove the tailnet mapping for port ${ String ( sharedWebPort ) } ${
765- result . explanation ? `: ${ result . explanation } ` : ""
766- } . Remove it with \`tailscale serve --https=${ String ( sharedWebPort ) } off\`.`,
767- ) ,
785+ const shared = yield * Effect . acquireRelease (
786+ shareDevServer ( {
787+ webPort : sharedWebPort ,
788+ // The backend binds 127.0.0.1 unless --host changes it. A wildcard
789+ // still answers there; `--host ::1` binds only the IPv6 loopback.
790+ ...( input . built
791+ ? {
792+ localTarget : {
793+ port : Number ( env . T3CODE_PORT ) ,
794+ host : [ "::1" , "[::1]" ] . includes ( input . host ?. trim ( ) ?? "" ) ? "[::1]" : "127.0.0.1" ,
795+ } ,
796+ }
797+ : { } ) ,
798+ } ) ,
799+ ( ) =>
800+ unshareDevServer ( sharedWebPort ) . pipe (
801+ Effect . flatMap ( ( result ) =>
802+ result . cleared
803+ ? Effect . void
804+ : Effect . logWarning (
805+ `[dev-runner] could not remove the tailnet mapping for port ${ String ( sharedWebPort ) } ${
806+ result . explanation ? `: ${ result . explanation } ` : ""
807+ } . Remove it with \`tailscale serve --https=${ String ( sharedWebPort ) } off\`.`,
808+ ) ,
809+ ) ,
768810 ) ,
769- ) ,
770811 ) . pipe (
771812 Effect . tapError ( ( error : DevShareError ) =>
772813 Effect . logWarning (
@@ -792,14 +833,21 @@ export const runDevRunnerWithInput = Effect.fn("dev-runner.runDevRunnerWithInput
792833 if ( input . devUrl === undefined ) {
793834 env . VITE_DEV_SERVER_URL = shared . url ;
794835 }
795- // A shared origin serves a remote browser, where unbundled dev's
796- // per-module requests each pay a tailnet round trip — a cold module
797- // graph takes minutes to first paint. Bundled dev collapses that to a
798- // few chunk requests.
799- if ( env . T3CODE_BUNDLED_DEV === undefined ) {
836+ if ( input . built ) {
837+ built = true ;
838+ env . T3CODE_BUILT_DEV = "1" ;
839+ } else if ( env . T3CODE_BUNDLED_DEV === undefined ) {
840+ // A shared origin serves a remote browser, where unbundled dev's
841+ // per-module requests each pay a tailnet round trip — a cold module
842+ // graph takes minutes to first paint. Bundled dev collapses that to a
843+ // few chunk requests.
800844 env . T3CODE_BUNDLED_DEV = "1" ;
801845 }
802846 yield * Effect . logInfo ( `[dev-runner] shared on tailnet: ${ shared . url } ` ) ;
847+ } else if ( input . built ) {
848+ yield * Effect . logWarning (
849+ "[dev-runner] --built needs the tailnet share; running the Vite dev server instead." ,
850+ ) ;
803851 }
804852 }
805853 }
@@ -812,7 +860,7 @@ export const runDevRunnerWithInput = Effect.fn("dev-runner.runDevRunnerWithInput
812860 env,
813861 } ) ;
814862
815- const args = [ ...MODE_ARGS [ input . mode ] , ...input . runArgs ] ;
863+ const args = [ ...( built ? BUILT_DEV_ARGS : MODE_ARGS [ input . mode ] ) , ...input . runArgs ] ;
816864 const spawnCommand = yield * resolveSpawnCommand ( "vp" , args , { env } ) ;
817865 const processContext = {
818866 mode : input . mode ,
@@ -920,6 +968,12 @@ const devRunnerCli = Command.make("dev-runner", {
920968 ) ,
921969 Flag . withFallbackConfig ( optionalBooleanConfig ( "T3CODE_DEV_SEED" ) ) ,
922970 ) ,
971+ built : Flag . Boolean ( "built" ) . pipe (
972+ Flag . withDescription (
973+ "With --share: serve a production web build from the backend instead of the Vite dev server. Rebuilds on change, no HMR, much smaller remote loads." ,
974+ ) ,
975+ Flag . withDefault ( false ) ,
976+ ) ,
923977 runArgs : Argument . String ( "run-arg" ) . pipe (
924978 Argument . withDescription ( "Additional Vite+ run args (pass after `--`)." ) ,
925979 Argument . variadic ( ) ,
0 commit comments