新版的 vue-cli 构建的项目没有 dev-server.js
如何配置 proxyTable 。
与之替代的是 webpack.dev.conf.js
配置文件。但是该工程并没有默认依赖插件 http-proxy-middleware
。
我尝试使用之前的配置方式,先安装了依赖,然后在 build/index.js
的 dev 中将 proxyTable 做如下配置:
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/api': {
target: 'http://api.xxx.com',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
},
// Various Dev Server settings
host: 'localhost', // can be overwritten by process.env.HOST
port: 8080, // can be overwritten by process.env.HOST, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
// Use Eslint Loader?
// If true, your code will be linted during bundling and
// linting errors and warnings will be shown in the console.
useEslint: true,
// If true, eslint errors and warnings will also be shown in the error overlay
// in the browser.
showEslintErrorsInOverlay: false,
/**
* Source Maps
*/
// https://webpack.js.org/configuration/devtool/#development
devtool: 'eval-source-map',
// If you have problems debugging vue-files in devtools,
// set this to false - it *may* help
// https://vue-loader.vuejs.org/en/options.html#cachebusting
cacheBusting: true,
// CSS Sourcemaps off by default because relative paths are "buggy"
// with this option, according to the CSS-Loader README
// (https://github.com/webpack/css-loader#sourcemaps)
// In our experience, they generally work as expected,
// just be aware of this issue when enabling this option.
cssSourceMap: false,
}
重新 run 之后发现不起作用,请求地址没有正确转换,仍然是 http://localhost:8080/api/xxx
这样的格式。
求助一下新版的 vue 脚手架构建的项目如何正确配置 proxyTable 。
说明:新版的 build 目录中没有 dev-server.js
和 dev-client.js
这两个文件,也没有默认依赖 http-proxy-middleware
插件。
在config目录下的index.js文件中有个dev对象,为其中配置proxyTable即可。
另外如果你想使用node.js写数据接口的话,可以在build文件夹下的webpack.dev.conf.js文件中,为devServer添加以下内容: