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'
7
7
8
8
describe ( 'mergeConfig' , ( ) => {
9
9
test ( 'handles configs with different alias schemas' , ( ) => {
10
- const baseConfig : UserConfigExport = {
10
+ const baseConfig = defineConfig ( {
11
11
resolve : {
12
12
alias : [
13
13
{
@@ -16,16 +16,16 @@ describe('mergeConfig', () => {
16
16
} ,
17
17
] ,
18
18
} ,
19
- }
19
+ } )
20
20
21
- const newConfig : UserConfigExport = {
21
+ const newConfig = defineConfig ( {
22
22
resolve : {
23
23
alias : {
24
24
bar : 'bar-value' ,
25
25
baz : 'baz-value' ,
26
26
} ,
27
27
} ,
28
- }
28
+ } )
29
29
30
30
const mergedConfig : UserConfigExport = {
31
31
resolve : {
Original file line number Diff line number Diff line change @@ -100,15 +100,26 @@ export interface ConfigEnv {
100
100
*/
101
101
export type AppType = 'spa' | 'mpa' | 'custom'
102
102
103
+ export type UserConfigFnObject = ( env : ConfigEnv ) => UserConfig
104
+ export type UserConfigFnPromise = ( env : ConfigEnv ) => Promise < UserConfig >
103
105
export 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
105
113
106
114
/**
107
115
* Type helper to make it easier to use vite.config.ts
108
116
* accepts a direct {@link UserConfig} object, or a function that returns it.
109
117
* The function receives a {@link ConfigEnv} object that exposes two properties:
110
118
* `command` (either `'build'` or `'serve'`), and `mode`.
111
119
*/
120
+ export function defineConfig ( config : UserConfig ) : UserConfig
121
+ export function defineConfig ( config : Promise < UserConfig > ) : Promise < UserConfig >
122
+ export function defineConfig ( config : UserConfigExport ) : UserConfigExport
112
123
export function defineConfig ( config : UserConfigExport ) : UserConfigExport {
113
124
return config
114
125
}
Original file line number Diff line number Diff line change 1
1
import path from 'node:path'
2
2
import { defineConfig } from 'vite'
3
3
4
- /** @type {import('vite').UserConfig } */
5
- // @ts -expect-error typecast
6
4
export default defineConfig ( {
7
5
base : '/foo' ,
8
6
publicDir : 'static' ,
Original file line number Diff line number Diff line change @@ -9,8 +9,6 @@ globalThis.window = {}
9
9
// @ts -expect-error refer to https://github.com/vitejs/vite/pull/11079
10
10
globalThis . location = new URL ( 'http://localhost/' )
11
11
12
- /** @type {import('vite').UserConfig } */
13
- // @ts -expect-error typecast
14
12
export default defineConfig ( {
15
13
build : {
16
14
cssTarget : 'chrome61' ,
Original file line number Diff line number Diff line change 1
1
import { defineConfig } from 'vite'
2
2
3
- /** @type {import('vite').UserConfig } */
4
- // @ts -expect-error typecast
5
3
export default defineConfig ( {
6
4
define : {
7
5
__EXP__ : 'false' ,
Original file line number Diff line number Diff line change @@ -2,8 +2,6 @@ import fs from 'node:fs'
2
2
import path from 'node:path'
3
3
import { defineConfig } from 'vite'
4
4
5
- /** @type {import('vite').UserConfig } */
6
- // @ts -expect-error typecast
7
5
export default defineConfig ( {
8
6
esbuild : {
9
7
supported : {
You can’t perform that action at this time.
0 commit comments