情况是这样的,自己在做练习,想使用swig模板,通过grunt + livereload来实现自动化。
首先我先设置了端口号为80
var port = normalizePort(process.env.PORT || '80');
var server = http.createServer(app);
server.listen(port);
同时也设置了默认请求
var index = require('./routes/index');
app.use('/', index);
这样在直接访问地址的时候,已经可以直接访问到index.html了,但是想通过grunt + livereload来实现自动化。
这样就用到了watch
/* 部分代码 */
watch: {
html:{
options:{
livereload:{
port: 80
}
},
files:['views/**/*.html']
}
}
也设置了grunt的default任务,执行grunt成功。
但是修改html文件,并不会实时生效,但是如果重启server就能生效了,这样我又想到加入shell。
shell:{
run:{
command:'node server.js --inline'
},
killall:{
command:'killall node'
}
}
watch: {
html:{
options:{
livereload:{
port: 80
} //livereload工具,浏览器安装插件后,不用重启服务器,不用刷新页面,好神奇的说
},
files:['views/**/*.html'], //如果swig的文件有变化,就执行任务
tasks:['shell:run']
}
}
但是还是不行,希望大家能给点儿帮助,谢谢。
另外请问一下,对livereload设置端口,到底有什么用呢?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
ringa_lee