想要实现热更新的同时只打开一次页面,一开始是这么写的
app.listen(port, function(){
console.log('服务已启动:http://localhost:8888/')
open('http://localhost:8888/',{
wait:true,
app:'chrome'
})
})
但是由于我使用了热更新,所以每保存一次就会重新打开一次页面 - -!
很显然这不是我想要的结果
所以使用了一个超级蠢的办法,新建个start文件,该文件只有一个作用,就是打开url
// start.js
const open = require("open");
open('http://localhost:8888/',{
wait:true,
app:'chrome'
})
然后在package.json中修改script命令
"scripts": {
"dev": "node start.js && nodemon --inspect index.js"
},
如果诸位大佬有好的办法,希望能够指点我一下下