@@ -29,6 +29,7 @@ import { safeStringToNumber } from './utils/number';
2929import { loadEnv } from './utils/env' ;
3030import { getPort } from 'get-port-please' ;
3131import { fileURLToPath , pathToFileURL } from 'node:url' ;
32+ import * as vite from 'vite' ;
3233
3334/**
3435 * Given an inline config, discover the config file if necessary, merge the results, resolve any
@@ -61,7 +62,7 @@ export async function resolveConfig(
6162
6263 // Merge it into the inline config
6364
64- const mergedConfig = await mergeInlineConfig ( inlineConfig , userConfig ) ;
65+ const mergedConfig = mergeInlineConfig ( inlineConfig , userConfig ) ;
6566
6667 // Apply defaults to make internal config.
6768
@@ -255,10 +256,10 @@ async function resolveManifestConfig(
255256/**
256257 * Merge the inline config and user config. Inline config is given priority. Defaults are not applied here.
257258 */
258- async function mergeInlineConfig (
259+ function mergeInlineConfig (
259260 inlineConfig : InlineConfig ,
260261 userConfig : UserConfig ,
261- ) : Promise < InlineConfig > {
262+ ) : InlineConfig {
262263 // Merge imports option
263264 const imports : InlineConfig [ 'imports' ] =
264265 inlineConfig . imports === false || userConfig . imports === false
@@ -277,11 +278,7 @@ async function mergeInlineConfig(
277278 const merged = defu ( inlineConfig , userConfig ) ;
278279
279280 // Builders
280- const builderConfig = await mergeBuilderConfig (
281- merged . logger ?? consola ,
282- inlineConfig ,
283- userConfig ,
284- ) ;
281+ const builderConfig = mergeBuilderConfig ( inlineConfig , userConfig ) ;
285282
286283 return {
287284 ...merged ,
@@ -566,25 +563,17 @@ const COMMAND_MODES: Record<WxtCommand, string> = {
566563 serve : 'development' ,
567564} ;
568565
569- export async function mergeBuilderConfig (
570- logger : Logger ,
566+ function mergeBuilderConfig (
571567 inlineConfig : InlineConfig ,
572568 userConfig : UserConfig ,
573- ) : Promise < Pick < InlineConfig , 'vite' > > {
574- const vite = await import ( 'vite' ) . catch ( ( err ) => {
575- logger . debug ( 'Failed to import vite:' , err ) ;
576- } ) ;
577- if ( vite ) {
578- return {
579- vite : async ( env ) => {
580- const resolvedInlineConfig = ( await inlineConfig . vite ?.( env ) ) ?? { } ;
581- const resolvedUserConfig = ( await userConfig . vite ?.( env ) ) ?? { } ;
582- return vite . mergeConfig ( resolvedUserConfig , resolvedInlineConfig ) ;
583- } ,
584- } ;
585- }
586-
587- throw Error ( 'Builder not found. Make sure vite is installed.' ) ;
569+ ) : Pick < InlineConfig , 'vite' > {
570+ return {
571+ vite : async ( env ) => {
572+ const resolvedInlineConfig = ( await inlineConfig . vite ?.( env ) ) ?? { } ;
573+ const resolvedUserConfig = ( await userConfig . vite ?.( env ) ) ?? { } ;
574+ return vite . mergeConfig ( resolvedUserConfig , resolvedInlineConfig ) ;
575+ } ,
576+ } ;
588577}
589578
590579export async function resolveWxtUserModules (
0 commit comments