fix: vite types (#3352)

* Re-export vite types and added them to zod schema

* Removed casted typed

* Changeset
This commit is contained in:
Juan Martín Seery 2022-05-12 13:55:29 -03:00 committed by GitHub
parent 7cd4b1bc12
commit 8685506174
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Export `ViteUserConfig` type

View file

@ -255,6 +255,10 @@ type ServerConfig = {
port?: number; port?: number;
}; };
export interface ViteUserConfig extends vite.UserConfig {
ssr?: vite.SSROptions;
}
/** /**
* Astro User Config * Astro User Config
* Docs: https://docs.astro.build/reference/configuration-reference/ * Docs: https://docs.astro.build/reference/configuration-reference/
@ -652,7 +656,7 @@ export interface AstroUserConfig {
* } * }
* ``` * ```
*/ */
vite?: vite.UserConfig & { ssr?: vite.SSROptions }; vite?: ViteUserConfig;
experimental?: { experimental?: {
/** /**

View file

@ -120,7 +120,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
const ssr = isBuildingToSSR(astroConfig); const ssr = isBuildingToSSR(astroConfig);
const out = ssr ? opts.buildConfig.server : astroConfig.outDir; const out = ssr ? opts.buildConfig.server : astroConfig.outDir;
const viteBuildConfig = { const viteBuildConfig: ViteConfigWithSSR = {
logLevel: 'error', logLevel: 'error',
mode: 'production', mode: 'production',
css: viteConfig.css, css: viteConfig.css,
@ -165,7 +165,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
base: astroConfig.base, base: astroConfig.base,
ssr: viteConfig.ssr, ssr: viteConfig.ssr,
resolve: viteConfig.resolve, resolve: viteConfig.resolve,
} as ViteConfigWithSSR; };
await runHookBuildSetup({ await runHookBuildSetup({
config: astroConfig, config: astroConfig,

View file

@ -1,4 +1,4 @@
import type { AstroConfig, AstroUserConfig, CLIFlags } from '../@types/astro'; import type { AstroConfig, AstroUserConfig, CLIFlags, ViteUserConfig } from '../@types/astro';
import type { Arguments as Flags } from 'yargs-parser'; import type { Arguments as Flags } from 'yargs-parser';
import type * as Postcss from 'postcss'; import type * as Postcss from 'postcss';
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki'; import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
@ -182,7 +182,9 @@ export const AstroConfigSchema = z.object({
.default([]), .default([]),
}) })
.default({}), .default({}),
vite: z.any().optional().default({}), vite: z
.custom<ViteUserConfig>((data) => data instanceof Object && !Array.isArray(data))
.default({}),
experimental: z experimental: z
.object({ .object({
ssr: z.boolean().optional().default(false), ssr: z.boolean().optional().default(false),