File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import type { Nitro } from "nitro/types" ;
22import { isTest } from "std-env" ;
33import { nitro as nitroPlugin } from "nitro/vite" ;
4+ import { resolveModulePath } from "exsolve" ;
45
56export async function viteBuild ( nitro : Nitro ) {
67 if ( nitro . options . dev ) {
78 throw new Error ( "Nitro dev CLI does not supports vite. Please use `vite dev` instead." ) ;
89 }
9- const { createBuilder } = ( await import (
10- ( nitro . options as any ) . __vitePkg__ || "vite"
11- ) ) as typeof import ( "vite" ) ;
10+
11+ const vitePkg = ( nitro . options as any ) . __vitePkg__ || "vite" ;
12+ const viteEntry = resolveModulePath ( vitePkg , { from : nitro . options . rootDir } ) ;
13+ const { createBuilder } = ( await import ( viteEntry ) ) as typeof import ( "vite" ) ;
1214
1315 const pluginInstance = nitroPlugin ( { _nitro : nitro } ) ;
16+
1417 ( globalThis as any ) . __nitro_build__ = true ;
18+
1519 const builder = await createBuilder ( {
1620 root : nitro . options . rootDir ,
1721 plugins : [ pluginInstance ] ,
1822 logLevel : isTest ? "warn" : undefined ,
1923 } ) ;
24+
2025 delete ( globalThis as any ) . __nitro_build__ ;
26+
2127 await builder . buildApp ( ) ;
2228}
You can’t perform that action at this time.
0 commit comments