From ffb2426e7547070ce075276a251a9259166e11cd Mon Sep 17 00:00:00 2001 From: alex8088 <244096523@qq.com> Date: Sun, 4 Dec 2022 01:24:25 +0800 Subject: [PATCH] feat: support mode and command conditional config --- src/config.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/config.ts b/src/config.ts index f4cd421..db9753e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -69,12 +69,14 @@ export type InlineConfig = Omit & { ignoreConfigWarning?: boolean } -export type UserConfigFn = () => UserConfigSchema | Promise +export type UserConfigFn = (env: ConfigEnv) => UserConfigSchema | Promise export type UserConfigExport = UserConfigSchema | Promise | UserConfigFn /** - * Type helper to make it easier to use `electron.vite.config.ts` + * Type helper to make it easier to use `electron.vite.config.*` * accepts a direct {@link UserConfig} object, or a function that returns it. + * The function receives a object that exposes two properties: + * `command` (either `'build'` or `'serve'`), and `mode`. */ export function defineConfig(config: UserConfigExport): UserConfigExport { return config @@ -236,7 +238,7 @@ export async function loadConfigFromFile( const bundled = await bundleConfigFile(resolvedPath, isESM) const userConfig = await loadConfigFormBundledFile(configRoot, resolvedPath, bundled.code, isESM) - const config = await (typeof userConfig === 'function' ? userConfig() : userConfig) + const config = await (typeof userConfig === 'function' ? userConfig(configEnv) : userConfig) if (!isObject(config)) { throw new Error(`config must export or return an object`) }