当使用 Vite
构建项目后,发现只有localhost
+ 端口
服务,没有 IP
+ 端口
服务
运行npm run dev
,终端提示Vite启动后提示Network: use '--host' to expose
package.json中脚本配置:
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
}
当运行 npm run dev | serve
命令时,会显示一下内容:
> vite-vue-demo@1.0.0
> vite | vite preview
vite v2.5.1 build preview server running at:
> Local: http://localhost:3000 | 5000/
> Network: use `--host` to expose
解决:
Configurationvite.config.js
export default defineConfig(({ mode })=>({
// ..
server: {
host: '0.0.0.0',
},
// ..
}))
执行npm run dev
命令
vite v2.5.1 dev server running at:
> Local: http://localhost:3000/
> Network: http://xxx.xx.xxx.xx:3000/
© Copyright Notice
THE END
There are currently no comments available