1. const path = require('path')
    2. const os = require('os')
    3. let ip = ''
    4. try {
    5. const network = os.networkInterfaces()
    6. ip = network[Object.keys(network)[0]][1].address
    7. } catch (e) {
    8. ip = '127.0.0.1';
    9. }
    10. module.exports = {
    11. dev: {
    12. // Paths
    13. assetsSubDirectory: 'static',
    14. assetsPublicPath: '/',
    15. proxyTable: {
    16. '/apiLwf': {
    17. target: 'http://47.106.225.238:9063',
    18. changeOrigin: true,
    19. pathRewrite:{
    20. '^/apiLwf':''
    21. }
    22. },
    23. },
    24. // Various Dev Server settings
    25. host: ip, // can be overwritten by process.env.HOST
    26. port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    27. autoOpenBrowser: false,
    28. errorOverlay: true,
    29. notifyOnErrors: true,
    30. poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
    31. devtool: 'cheap-module-eval-source-map',
    32. cacheBusting: true,
    33. cssSourceMap: true
    34. },
    35. build: {
    36. // Template for index.html
    37. index: path.resolve(__dirname, '../uploadFace/index.html'),
    38. // Paths
    39. assetsRoot: path.resolve(__dirname, '../uploadFace'),
    40. assetsSubDirectory: 'static',
    41. assetsPublicPath: '/uploadFace/', // 浏览器直接访问
    42. productionSourceMap: false,
    43. devtool: '#source-map',
    44. productionGzip: false,
    45. productionGzipExtensions: ['js', 'css'],
    46. bundleAnalyzerReport: process.env.npm_config_report
    47. }
    48. }
    1. 方法一:
    2. const os = require('os')
    3. let localhost = ''
    4. try {
    5. const network = os.networkInterfaces()
    6. localhost = network[Object.keys(network)[0]][1].address
    7. } catch (e) {
    8. localhost = 'localhost';
    9. }
    10. 方法二:
    11. npm i address -D
    12. const address = require('address')
    13. const localhost = address.ip() || 'localhost'