diff --git a/vue.config.js b/vue.config.js index 7b9d2db..6a5efcc 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,12 +1,27 @@ 'use strict' const path = require('path') const pkg = require('./package.json') +const os = require('os') function resolve(dir) { return path.join(__dirname, dir) } +function getIPAdress() { + let interfaces = os.networkInterfaces() + for (let devName in interfaces) { + let iface = interfaces[devName] + for (let i = 0; i < iface.length; i++) { + let alias = iface[i] + if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) { + return alias.address + } + } + } +} + const name = pkg.name || 'vue-element-admin' // page title +const host = getIPAdress() const port = 9527 // dev port // All configuration item explanations can be find in https://cli.vuejs.org/config/ @@ -24,6 +39,7 @@ module.exports = { lintOnSave: process.env.NODE_ENV === 'development' ? 'error' : false, productionSourceMap: false, devServer: { + host: host, port: port, open: true, overlay: { @@ -34,7 +50,7 @@ module.exports = { // change xxx-api/login => mock/login // detail: https://cli.vuejs.org/config/#devserver-proxy [process.env.VUE_APP_BASE_API]: { - target: `http://localhost:${port}/mock`, + target: `http://${host}:${port}/mock`, changeOrigin: true, pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: ''