我是Grunt和Javascript/Coffeescript的新手.
我们在一个包含数百个.coffee文件的大型项目中使用Grunt.由于Grunt编译了所有的咖啡文件(尽管只有一个文件已经更改),我最初的问题是如何让Grunt只编译一个更改的文件.使用stackoverflow我能够回答这个问题,谢谢大家:)
但现在似乎已实施的解决方案打破了实时重载.当我从"grunt服务器"开始并在浏览器中显示我的页面时,一切看起来都很好.然后我更改一个.coffee文件并保存.文件被编译(我已检查),但我的浏览器从未被重新加载.只有当我手动重新加载浏览器时,才会显示新修改的代码.
所以问题是:为什么livereload不再有效?
我不知道这是否重要,但Gruntfile是在旧版本中使用yeoman创建的(使用grunt-regarde).我使用grunt-contrib-watch和buildin livereload将package.json和Gruntfile更新为更新的规范.没有grunt.event.on一切正常.
来源(部分):
grunt.initConfig({
watch: {
coffee: {
files: ['<%= yeoman.app %>/coffeescripts/**/*.coffee'],
tasks: ['coffee:app'],
options: {
nospawn: true
},
},
compass: {
files: ['<%= yeoman.app %>/styles/**/*.{scss,sass}'],
tasks: ['compass']
},
templates: {
files: ['<%= yeoman.app %>/templates/**/*.tpl'],
tasks: ['handlebars']
},
livereload: {
options: {
livereload: LIVERELOAD_PORT
},
files: [
'<%= yeoman.app %>/*.html',
'<%= yeoman.tmp %>/styles/**/*.css',
'<%= yeoman.tmp %>/scripts/**/*.js',
'<%= yeoman.tmp %>/spec/**/*.js',
'<%= yeoman.app %>/img/{,*/}*.{png,jpg,jpeg,webp}',
]
}
},
coffee: {
app: {
expand: true,
cwd: …Run Code Online (Sandbox Code Playgroud) javascript coffeescript gruntjs livereload grunt-contrib-watch