@@ -224,14 +224,31 @@ export class BundlerCompilerService
224
224
} ) ;
225
225
226
226
childProcess . on ( "close" , async ( arg : any ) => {
227
- await this . $cleanupService . removeKillProcess (
228
- childProcess . pid . toString ( ) ,
229
- ) ;
230
-
231
227
const exitCode = typeof arg === "number" ? arg : arg && arg . code ;
232
228
this . $logger . trace (
233
229
`${ capitalizeFirstLetter ( projectData . bundler ) } process exited with code ${ exitCode } when we expected it to be long living with watch.` ,
234
230
) ;
231
+ if ( this . getBundler ( ) === "vite" && exitCode === 0 ) {
232
+ // note experimental: investigate watch mode
233
+ const bundlePath = path . join (
234
+ projectData . projectDir ,
235
+ "dist/bundle.js" ,
236
+ ) ;
237
+ console . log ( "bundlePath:" , bundlePath ) ;
238
+ const data = {
239
+ files : [ bundlePath ] ,
240
+ hasOnlyHotUpdateFiles : false ,
241
+ hmrData : { } ,
242
+ platform : platformData . platformNameLowerCase ,
243
+ } ;
244
+ this . emit ( BUNDLER_COMPILATION_COMPLETE , data ) ;
245
+ resolve ( 1 ) ;
246
+ return ;
247
+ }
248
+
249
+ await this . $cleanupService . removeKillProcess (
250
+ childProcess . pid . toString ( ) ,
251
+ ) ;
235
252
const error : any = new Error (
236
253
`Executing ${ projectData . bundler } failed with exit code ${ exitCode } .` ,
237
254
) ;
@@ -341,12 +358,15 @@ export class BundlerCompilerService
341
358
projectData ,
342
359
prepareData ,
343
360
) ;
344
- const envParams = await this . buildEnvCommandLineParams (
345
- envData ,
346
- platformData ,
347
- projectData ,
348
- prepareData ,
349
- ) ;
361
+ const isVite = this . getBundler ( ) === "vite" ;
362
+ const envParams = isVite
363
+ ? [ `--mode=${ platformData . platformNameLowerCase } ` ]
364
+ : await this . buildEnvCommandLineParams (
365
+ envData ,
366
+ platformData ,
367
+ projectData ,
368
+ prepareData ,
369
+ ) ;
350
370
const additionalNodeArgs =
351
371
semver . major ( process . version ) <= 8 ? [ "--harmony" ] : [ ] ;
352
372
@@ -366,8 +386,10 @@ export class BundlerCompilerService
366
386
...envParams ,
367
387
] . filter ( Boolean ) ;
368
388
369
- if ( prepareData . watch ) {
370
- args . push ( "--watch" ) ;
389
+ if ( ! isVite ) {
390
+ if ( prepareData . watch ) {
391
+ args . push ( "--watch" ) ;
392
+ }
371
393
}
372
394
373
395
const stdio = prepareData . watch ? [ "ipc" ] : "inherit" ;
@@ -391,6 +413,8 @@ export class BundlerCompilerService
391
413
} ) ;
392
414
}
393
415
416
+ console . log ( "args:" , args ) ;
417
+
394
418
const childProcess = this . $childProcess . spawn (
395
419
process . execPath ,
396
420
args ,
@@ -670,7 +694,15 @@ export class BundlerCompilerService
670
694
private getBundlerExecutablePath ( projectData : IProjectData ) : string {
671
695
const bundler = this . getBundler ( ) ;
672
696
673
- if ( this . isModernBundler ( projectData ) ) {
697
+ if ( bundler === "vite" ) {
698
+ const packagePath = resolvePackagePath ( `vite` , {
699
+ paths : [ projectData . projectDir ] ,
700
+ } ) ;
701
+
702
+ if ( packagePath ) {
703
+ return path . resolve ( packagePath , "bin" , "vite.js" ) ;
704
+ }
705
+ } else if ( this . isModernBundler ( projectData ) ) {
674
706
const packagePath = resolvePackagePath ( `@nativescript/${ bundler } ` , {
675
707
paths : [ projectData . projectDir ] ,
676
708
} ) ;
0 commit comments