const fs = require('fs'); const path = require('path'); const url = require('url'); let info = { host: '127.0.0.1', port: 5001, publicPath: 'http://127.0.0.1:5001/' }; try { let dev = JSON.parse(fs.readFileSync(path.join(__dirname, '../../.devhost'))); if (dev.publicPath) { let urlObj = url.parse(dev.publicPath); info = { host: urlObj.hostname, port: urlObj.port, publicPath: dev.publicPath }; } else { info.host = dev.host; info.publicPath = `http://${info.host}:${info.port}/`; } } catch (e) { if (!process.env.NODE_ENV) { console.error(e); console.warn(` 推荐在项目主目录建一个 .devhost 文件,内容为 { "host": "127.0.0.1" } `); } } module.exports = info;