File tree Expand file tree Collapse file tree 6 files changed +16
-13
lines changed
Expand file tree Collapse file tree 6 files changed +16
-13
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { mergeConfig } from '../publicUtils'
77
88describe ( 'mergeConfig' , ( ) => {
99 test ( 'handles configs with different alias schemas' , ( ) => {
10- const baseConfig : UserConfigExport = {
10+ const baseConfig = defineConfig ( {
1111 resolve : {
1212 alias : [
1313 {
@@ -16,16 +16,16 @@ describe('mergeConfig', () => {
1616 } ,
1717 ] ,
1818 } ,
19- }
19+ } )
2020
21- const newConfig : UserConfigExport = {
21+ const newConfig = defineConfig ( {
2222 resolve : {
2323 alias : {
2424 bar : 'bar-value' ,
2525 baz : 'baz-value' ,
2626 } ,
2727 } ,
28- }
28+ } )
2929
3030 const mergedConfig : UserConfigExport = {
3131 resolve : {
Original file line number Diff line number Diff line change @@ -100,15 +100,26 @@ export interface ConfigEnv {
100100 */
101101export type AppType = 'spa' | 'mpa' | 'custom'
102102
103+ export type UserConfigFnObject = ( env : ConfigEnv ) => UserConfig
104+ export type UserConfigFnPromise = ( env : ConfigEnv ) => Promise < UserConfig >
103105export type UserConfigFn = ( env : ConfigEnv ) => UserConfig | Promise < UserConfig >
104- export type UserConfigExport = UserConfig | Promise < UserConfig > | UserConfigFn
106+
107+ export type UserConfigExport =
108+ | UserConfig
109+ | Promise < UserConfig >
110+ | UserConfigFnObject
111+ | UserConfigFnPromise
112+ | UserConfigFn
105113
106114/**
107115 * Type helper to make it easier to use vite.config.ts
108116 * accepts a direct {@link UserConfig} object, or a function that returns it.
109117 * The function receives a {@link ConfigEnv} object that exposes two properties:
110118 * `command` (either `'build'` or `'serve'`), and `mode`.
111119 */
120+ export function defineConfig ( config : UserConfig ) : UserConfig
121+ export function defineConfig ( config : Promise < UserConfig > ) : Promise < UserConfig >
122+ export function defineConfig ( config : UserConfigExport ) : UserConfigExport
112123export function defineConfig ( config : UserConfigExport ) : UserConfigExport {
113124 return config
114125}
Original file line number Diff line number Diff line change 11import path from 'node:path'
22import { defineConfig } from 'vite'
33
4- /** @type {import('vite').UserConfig } */
5- // @ts -expect-error typecast
64export default defineConfig ( {
75 base : '/foo' ,
86 publicDir : 'static' ,
Original file line number Diff line number Diff line change @@ -9,8 +9,6 @@ globalThis.window = {}
99// @ts -expect-error refer to https://github.com/vitejs/vite/pull/11079
1010globalThis . location = new URL ( 'http://localhost/' )
1111
12- /** @type {import('vite').UserConfig } */
13- // @ts -expect-error typecast
1412export default defineConfig ( {
1513 build : {
1614 cssTarget : 'chrome61' ,
Original file line number Diff line number Diff line change 11import { defineConfig } from 'vite'
22
3- /** @type {import('vite').UserConfig } */
4- // @ts -expect-error typecast
53export default defineConfig ( {
64 define : {
75 __EXP__ : 'false' ,
Original file line number Diff line number Diff line change @@ -2,8 +2,6 @@ import fs from 'node:fs'
22import path from 'node:path'
33import { defineConfig } from 'vite'
44
5- /** @type {import('vite').UserConfig } */
6- // @ts -expect-error typecast
75export default defineConfig ( {
86 esbuild : {
97 supported : {
You can’t perform that action at this time.
0 commit comments