Skip to content

Commit

Permalink
fix: devServer proxy config should support array type
Browse files Browse the repository at this point in the history
  • Loading branch information
北灼 committed Nov 4, 2022
1 parent ea4c98a commit 7fb9ada
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/@vue/cli-service/lib/util/prepareProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function prepareProxy (proxy, appPublicFolder) {
if (!proxy) {
return undefined
}
if (Array.isArray(proxy) || (typeof proxy !== 'object' && typeof proxy !== 'string')) {
if (typeof proxy !== 'object' && typeof proxy !== 'string') {
console.log(
chalk.red(
'When specified, "proxy" in package.json must be a string or an object.'
Expand Down Expand Up @@ -117,6 +117,14 @@ module.exports = function prepareProxy (proxy, appPublicFolder) {
]
}

// Support proxy as an array
if (Array.isArray(proxy)) {
return proxy.map(item => {
if (typeof item === 'function') return item
return Object.assign({}, defaultConfig, item)
})
}

// Otherwise, proxy is an object so create an array of proxies to pass to webpackDevServer
return Object.keys(proxy).map(context => {
const config = proxy[context]
Expand Down

0 comments on commit 7fb9ada

Please sign in to comment.