@@ -20,7 +20,6 @@ import type { Config } from "../config";
20
20
import type { Entry } from "../entry" ;
21
21
import type { AssetPaths } from "../sites" ;
22
22
import type { CfWorkerInit } from "../worker" ;
23
- import type { EsbuildBundle } from "./use-esbuild" ;
24
23
25
24
export type DevProps = {
26
25
name ?: string ;
@@ -58,10 +57,6 @@ export type DevProps = {
58
57
} ;
59
58
60
59
export function DevImplementation ( props : DevProps ) : JSX . Element {
61
- const directory = useTmpDir ( ) ;
62
-
63
- useCustomBuild ( props . entry , props . build ) ;
64
-
65
60
if ( props . public && props . entry . format === "service-worker" ) {
66
61
throw new Error (
67
62
"You cannot use the service-worker format with a `public` directory."
@@ -86,37 +81,16 @@ export function DevImplementation(props: DevProps): JSX.Element {
86
81
) ;
87
82
}
88
83
89
- const bundle = useEsbuild ( {
90
- entry : props . entry ,
91
- destination : directory ,
92
- staticRoot : props . public ,
93
- jsxFactory : props . jsxFactory ,
94
- rules : props . rules ,
95
- jsxFragment : props . jsxFragment ,
96
- serveAssetsFromWorker : ! ! props . public ,
97
- tsconfig : props . tsconfig ,
98
- minify : props . minify ,
99
- nodeCompat : props . nodeCompat ,
100
- } ) ;
101
-
102
84
// only load the UI if we're running in a supported environment
103
85
const { isRawModeSupported } = useStdin ( ) ;
104
86
return isRawModeSupported ? (
105
- < InteractiveDevSession { ...props } bundle = { bundle } />
87
+ < InteractiveDevSession { ...props } />
106
88
) : (
107
- < DevSession
108
- { ...props }
109
- bundle = { bundle }
110
- local = { props . initialMode === "local" }
111
- />
89
+ < DevSession { ...props } local = { props . initialMode === "local" } />
112
90
) ;
113
91
}
114
92
115
- type InteractiveDevSessionProps = DevProps & {
116
- bundle : EsbuildBundle | undefined ;
117
- } ;
118
-
119
- function InteractiveDevSession ( props : InteractiveDevSessionProps ) {
93
+ function InteractiveDevSession ( props : DevProps ) {
120
94
const toggles = useHotkeys (
121
95
{
122
96
local : props . initialMode === "local" ,
@@ -149,13 +123,33 @@ function InteractiveDevSession(props: InteractiveDevSessionProps) {
149
123
) ;
150
124
}
151
125
152
- type DevSessionProps = InteractiveDevSessionProps & { local : boolean } ;
126
+ type DevSessionProps = DevProps & {
127
+ local : boolean ;
128
+ } ;
153
129
154
130
function DevSession ( props : DevSessionProps ) {
131
+ useCustomBuild ( props . entry , props . build ) ;
132
+
133
+ const directory = useTmpDir ( ) ;
134
+
135
+ const bundle = useEsbuild ( {
136
+ entry : props . entry ,
137
+ destination : directory ,
138
+ staticRoot : props . public ,
139
+ jsxFactory : props . jsxFactory ,
140
+ rules : props . rules ,
141
+ jsxFragment : props . jsxFragment ,
142
+ // In dev for remote mode, we serve --experimental-assets from the local proxy before we send the request to the worker.
143
+ serveAssetsFromWorker : ! ! props . public && ! ! props . local ,
144
+ tsconfig : props . tsconfig ,
145
+ minify : props . minify ,
146
+ nodeCompat : props . nodeCompat ,
147
+ } ) ;
148
+
155
149
return props . local ? (
156
150
< Local
157
151
name = { props . name }
158
- bundle = { props . bundle }
152
+ bundle = { bundle }
159
153
format = { props . entry . format }
160
154
compatibilityDate = { props . compatibilityDate }
161
155
compatibilityFlags = { props . compatibilityFlags }
@@ -172,7 +166,7 @@ function DevSession(props: DevSessionProps) {
172
166
) : (
173
167
< Remote
174
168
name = { props . name }
175
- bundle = { props . bundle }
169
+ bundle = { bundle }
176
170
format = { props . entry . format }
177
171
accountId = { props . accountId }
178
172
bindings = { props . bindings }
0 commit comments