vue.config.js 是一個可選的配置文件,項目初始化時,可能會需要自行創建vue.config.js文件來對項目進行控制。
詳情參考vue-cli官網
https://cli.vuejs.org/zh/config/#vue-config-js
當前項目中,常用配置如下
module.exports = {
outputDir: 'dist', //build輸出目錄
assetsDir: 'assets', //靜態資源目錄(js, css, img)
lintOnSave: false, //是否開啟eslint
publicPath: "./",
devServer: {
open: true, //是否自動彈出瀏覽器頁面
// host: "localhost",
port: '8081',
https: false,
hotOnly: false,
proxy: {//跨域配置
'/api/v1/client': {
target: "http://192.168.1.133:7100", //API服務器的地址
changeOrigin: true, // 虛擬的站點需要更管origin
},
'/api': {
target: "http://192.104.1.13", //API服務器的地址
changeOrigin: true, // 虛擬的站點需要更管origin
// ws: true, //代理websockets
// pathRewrite: { //重寫路徑 比如'/api/aaa/ccc'重寫為'/aaa/ccc'
// '^/api/v1/stock-auth': '',
// }
},
},
}
}
devServer.proxy對象可通過添加多個key來進行精準配置。