const path = require('path')const os = require('os')let ip = ''try { const network = os.networkInterfaces() ip = network[Object.keys(network)[0]][1].address} catch (e) { ip = '127.0.0.1';}module.exports = { dev: { // Paths assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { '/apiLwf': { target: 'http://47.106.225.238:9063', changeOrigin: true, pathRewrite:{ '^/apiLwf':'' } }, }, // Various Dev Server settings host: ip, // can be overwritten by process.env.HOST port: 8080, // can be overwritten by process.env.PORT, 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- devtool: 'cheap-module-eval-source-map', cacheBusting: true, cssSourceMap: true }, build: { // Template for index.html index: path.resolve(__dirname, '../uploadFace/index.html'), // Paths assetsRoot: path.resolve(__dirname, '../uploadFace'), assetsSubDirectory: 'static', assetsPublicPath: '/uploadFace/', // 浏览器直接访问 productionSourceMap: false, devtool: '#source-map', productionGzip: false, productionGzipExtensions: ['js', 'css'], bundleAnalyzerReport: process.env.npm_config_report }}
方法一:const os = require('os')let localhost = ''try { const network = os.networkInterfaces() localhost = network[Object.keys(network)[0]][1].address} catch (e) { localhost = 'localhost';}方法二:npm i address -Dconst address = require('address')const localhost = address.ip() || 'localhost'