Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: a defineConfig API from @vue/cli-service for better typing support in vue.config.js #6355

Merged
merged 3 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ module.exports = {
}
```

Or, you can use the `defineConfig` helper from `@vue/cli-service`, which could provide better intellisense support:

```js
// vue.config.js
const { defineConfig } = require('@vue/cli-service')

module.exports = defineConfig({
// options...
})
```

### baseUrl

Deprecated since Vue CLI 3.3, please use [`publicPath`](#publicPath) instead.
Expand Down
12 changes: 12 additions & 0 deletions docs/zh/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ module.exports = {
// 选项...
}
```

或者,你也可以使用 `@vue/cli-service` 提供的 `defineConfig` 帮手函数,以获得更好的类型提示:

```js
// vue.config.js
const { defineConfig } = require('@vue/cli-service')

module.exports = defineConfig({
// 选项
})
```

### baseUrl

从 Vue CLI 3.3 起已弃用,请使用[`publicPath`](#publicpath)。
Expand Down
3 changes: 3 additions & 0 deletions packages/@vue/cli-service/lib/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,6 @@ function cloneRuleNames (to, from) {
}
})
}

/** @type {import('../types/index').defineConfig} */
module.exports.defineConfig = (config) => config
5 changes: 3 additions & 2 deletions packages/@vue/cli-service/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ChainableConfig = require('webpack-chain')
import webpack = require('webpack')
import WebpackDevServer = require('webpack-dev-server')
import express = require('express') // @types/webpack-dev-server depends on @types/express
import { ProjectOptions } from './ProjectOptions'
import { ProjectOptions, ConfigFunction } from './ProjectOptions'

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

Expand Down Expand Up @@ -134,4 +134,5 @@ type ServicePlugin = (
) => any

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