Skip to content

Commit 54d5f78

Browse files
authored
feat: a defineConfig API from @vue/cli-service for better typing support in vue.config.js (#6355)
1 parent 27b4263 commit 54d5f78

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

docs/config/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ module.exports = {
2727
}
2828
```
2929

30+
Or, you can use the `defineConfig` helper from `@vue/cli-service`, which could provide better intellisense support:
31+
32+
```js
33+
// vue.config.js
34+
const { defineConfig } = require('@vue/cli-service')
35+
36+
module.exports = defineConfig({
37+
// options...
38+
})
39+
```
40+
3041
### baseUrl
3142

3243
Deprecated since Vue CLI 3.3, please use [`publicPath`](#publicPath) instead.

docs/zh/config/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ module.exports = {
2626
// 选项...
2727
}
2828
```
29+
30+
或者,你也可以使用 `@vue/cli-service` 提供的 `defineConfig` 帮手函数,以获得更好的类型提示:
31+
32+
```js
33+
// vue.config.js
34+
const { defineConfig } = require('@vue/cli-service')
35+
36+
module.exports = defineConfig({
37+
// 选项
38+
})
39+
```
40+
2941
### baseUrl
3042

3143
从 Vue CLI 3.3 起已弃用,请使用[`publicPath`](#publicpath)

packages/@vue/cli-service/lib/Service.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,6 @@ function cloneRuleNames (to, from) {
436436
}
437437
})
438438
}
439+
440+
/** @type {import('../types/index').defineConfig} */
441+
module.exports.defineConfig = (config) => config

packages/@vue/cli-service/types/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ChainableConfig = require('webpack-chain')
33
import webpack = require('webpack')
44
import WebpackDevServer = require('webpack-dev-server')
55
import express = require('express') // @types/webpack-dev-server depends on @types/express
6-
import { ProjectOptions } from './ProjectOptions'
6+
import { ProjectOptions, ConfigFunction } from './ProjectOptions'
77

88
type RegisterCommandFn = (args: minimist.ParsedArgs, rawArgv: string[]) => any
99

@@ -134,4 +134,5 @@ type ServicePlugin = (
134134
) => any
135135

136136
export { ProjectOptions, ServicePlugin, PluginAPI }
137-
export { ConfigFunction } from './ProjectOptions'
137+
type UserConfig = ProjectOptions | ConfigFunction
138+
export function defineConfig(config: UserConfig): UserConfig

0 commit comments

Comments
 (0)