@@ -154,25 +154,28 @@ const config = {
154
154
} ,
155
155
] ;
156
156
157
- const redirectsFile = path . join ( import . meta. dirname , "public/_redirects" ) ;
158
- await fs . writeFile (
159
- redirectsFile ,
160
- redirects
161
- . map ( ( { source, destination, permanent } ) => {
162
- return `${ source } ${ destination } ${ permanent ? 308 : 307 } ` ;
163
- } )
164
- . join ( "\n" ) +
165
- "\n" +
166
- splatRedirects
167
- . map ( ( { source, destination, permanent } ) => {
168
- const splatPattern = / : ( \w + ) \* $ / ;
169
- assert . match ( source , splatPattern ) ;
170
- assert . match ( destination , splatPattern ) ;
171
- return `${ source . replace ( splatPattern , "*" ) } ${ destination . replace ( splatPattern , ":splat" ) } ${ permanent ? 308 : 307 } ` ;
172
- } )
173
- . join ( "\n" ) ,
174
- "utf8" ,
175
- ) ;
157
+ if ( process . env . NODE_ENV === "production" ) {
158
+ const redirectsFile = path . join ( import . meta. dirname , "out/_redirects" ) ;
159
+ await fs . mkdir ( path . dirname ( redirectsFile ) ) ;
160
+ await fs . writeFile (
161
+ redirectsFile ,
162
+ redirects
163
+ . map ( ( { source, destination, permanent } ) => {
164
+ return `${ source } ${ destination } ${ permanent ? 308 : 307 } ` ;
165
+ } )
166
+ . join ( "\n" ) +
167
+ "\n" +
168
+ splatRedirects
169
+ . map ( ( { source, destination, permanent } ) => {
170
+ const splatPattern = / : ( \w + ) \* $ / ;
171
+ assert . match ( source , splatPattern ) ;
172
+ assert . match ( destination , splatPattern ) ;
173
+ return `${ source . replace ( splatPattern , "*" ) } ${ destination . replace ( splatPattern , ":splat" ) } ${ permanent ? 308 : 307 } ` ;
174
+ } )
175
+ . join ( "\n" ) ,
176
+ "utf8" ,
177
+ ) ;
178
+ }
176
179
177
180
return [ ...redirects , ...splatRedirects ] ;
178
181
} ,
0 commit comments