From 1a0130ab4f88316879c063350160948170738e07 Mon Sep 17 00:00:00 2001 From: alex8088 <244096523@qq.com> Date: Sun, 1 May 2022 00:18:21 +0800 Subject: [PATCH] fix: throw error when vite.config.* file in root (#3) --- src/config.ts | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/config.ts b/src/config.ts index 5781c66..c9b6078 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,7 +1,16 @@ import * as path from 'path' import * as fs from 'fs' import colors from 'picocolors' -import { UserConfig as ViteConfig, ConfigEnv, Plugin, LogLevel, createLogger, mergeConfig, normalizePath } from 'vite' +import { + UserConfig as ViteConfig, + UserConfigExport as UserViteConfigExport, + ConfigEnv, + Plugin, + LogLevel, + createLogger, + mergeConfig, + normalizePath +} from 'vite' import { build } from 'esbuild' import { electronMainVitePlugin, electronPreloadVitePlugin, electronRendererVitePlugin } from './plugin' @@ -15,19 +24,40 @@ export interface UserConfig { * * https://cn.vitejs.dev/config/ */ - main?: ViteConfig + main?: ViteConfig & { configFile?: string | false } /** * Vite config options for electron renderer process * * https://cn.vitejs.dev/config/ */ - renderer?: ViteConfig + renderer?: ViteConfig & { configFile?: string | false } /** * Vite config options for electron preload files * * https://cn.vitejs.dev/config/ */ - preload?: ViteConfig + preload?: ViteConfig & { configFile?: string | false } +} + +export interface UserConfigSchema { + /** + * Vite config options for electron main process + * + * https://cn.vitejs.dev/config/ + */ + main?: UserViteConfigExport + /** + * Vite config options for electron renderer process + * + * https://cn.vitejs.dev/config/ + */ + renderer?: UserViteConfigExport + /** + * Vite config options for electron preload files + * + * https://cn.vitejs.dev/config/ + */ + preload?: UserViteConfigExport } export type InlineConfig = Omit & { @@ -36,7 +66,7 @@ export type InlineConfig = Omit & { ignoreConfigWarning?: boolean } -export type UserConfigExport = UserConfig | Promise +export type UserConfigExport = UserConfigSchema | Promise /** * Type helper to make it easier to use `electron.vite.config.ts` @@ -99,6 +129,7 @@ export async function resolveConfig( mergePlugins(mainViteConfig, electronMainVitePlugin({ root })) loadResult.config.main = mainViteConfig + loadResult.config.main.configFile = false } if (loadResult.config.preload) { @@ -110,6 +141,7 @@ export async function resolveConfig( mergePlugins(preloadViteConfig, electronPreloadVitePlugin({ root })) loadResult.config.preload = preloadViteConfig + loadResult.config.preload.configFile = false } if (loadResult.config.renderer) { @@ -122,6 +154,7 @@ export async function resolveConfig( mergePlugins(rendererViteConfig, electronRendererVitePlugin({ root })) loadResult.config.renderer = rendererViteConfig + loadResult.config.renderer.configFile = false } userConfig = loadResult.config