Skip to content

Commit

Permalink
fix: vite types (#3352)
Browse files Browse the repository at this point in the history
* Re-export vite types and added them to zod schema

* Removed casted typed

* Changeset
  • Loading branch information
JuanM04 authored May 12, 2022
1 parent 7cd4b1b commit 8685506
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-gorillas-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Export `ViteUserConfig` type
6 changes: 5 additions & 1 deletion packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ type ServerConfig = {
port?: number;
};

export interface ViteUserConfig extends vite.UserConfig {
ssr?: vite.SSROptions;
}

/**
* Astro User Config
* Docs: https://docs.astro.build/reference/configuration-reference/
Expand Down Expand Up @@ -652,7 +656,7 @@ export interface AstroUserConfig {
* }
* ```
*/
vite?: vite.UserConfig & { ssr?: vite.SSROptions };
vite?: ViteUserConfig;

experimental?: {
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
const ssr = isBuildingToSSR(astroConfig);
const out = ssr ? opts.buildConfig.server : astroConfig.outDir;

const viteBuildConfig = {
const viteBuildConfig: ViteConfigWithSSR = {
logLevel: 'error',
mode: 'production',
css: viteConfig.css,
Expand Down Expand Up @@ -165,7 +165,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
base: astroConfig.base,
ssr: viteConfig.ssr,
resolve: viteConfig.resolve,
} as ViteConfigWithSSR;
};

await runHookBuildSetup({
config: astroConfig,
Expand Down
6 changes: 4 additions & 2 deletions packages/astro/src/core/config.ts
Original file line number Diff line number Diff line change
@@ -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 * as Postcss from 'postcss';
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
Expand Down Expand Up @@ -182,7 +182,9 @@ export const AstroConfigSchema = z.object({
.default([]),
})
.default({}),
vite: z.any().optional().default({}),
vite: z
.custom<ViteUserConfig>((data) => data instanceof Object && !Array.isArray(data))
.default({}),
experimental: z
.object({
ssr: z.boolean().optional().default(false),
Expand Down

0 comments on commit 8685506

Please sign in to comment.