@@ -224,14 +224,31 @@ export class BundlerCompilerService
224224 } ) ;
225225
226226 childProcess . on ( "close" , async ( arg : any ) => {
227- await this . $cleanupService . removeKillProcess (
228- childProcess . pid . toString ( ) ,
229- ) ;
230-
231227 const exitCode = typeof arg === "number" ? arg : arg && arg . code ;
232228 this . $logger . trace (
233229 `${ capitalizeFirstLetter ( projectData . bundler ) } process exited with code ${ exitCode } when we expected it to be long living with watch.` ,
234230 ) ;
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+ ) ;
235252 const error : any = new Error (
236253 `Executing ${ projectData . bundler } failed with exit code ${ exitCode } .` ,
237254 ) ;
@@ -341,12 +358,15 @@ export class BundlerCompilerService
341358 projectData ,
342359 prepareData ,
343360 ) ;
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+ ) ;
350370 const additionalNodeArgs =
351371 semver . major ( process . version ) <= 8 ? [ "--harmony" ] : [ ] ;
352372
@@ -366,8 +386,10 @@ export class BundlerCompilerService
366386 ...envParams ,
367387 ] . filter ( Boolean ) ;
368388
369- if ( prepareData . watch ) {
370- args . push ( "--watch" ) ;
389+ if ( ! isVite ) {
390+ if ( prepareData . watch ) {
391+ args . push ( "--watch" ) ;
392+ }
371393 }
372394
373395 const stdio = prepareData . watch ? [ "ipc" ] : "inherit" ;
@@ -391,6 +413,8 @@ export class BundlerCompilerService
391413 } ) ;
392414 }
393415
416+ console . log ( "args:" , args ) ;
417+
394418 const childProcess = this . $childProcess . spawn (
395419 process . execPath ,
396420 args ,
@@ -670,7 +694,15 @@ export class BundlerCompilerService
670694 private getBundlerExecutablePath ( projectData : IProjectData ) : string {
671695 const bundler = this . getBundler ( ) ;
672696
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 ) ) {
674706 const packagePath = resolvePackagePath ( `@nativescript/${ bundler } ` , {
675707 paths : [ projectData . projectDir ] ,
676708 } ) ;
0 commit comments