I am new to Grunt and Javascript / Coffeescript in general.
We use Grunt in a fairly large project with hundreds of files. coffee. Since Grunt compiles all cookies (although only one file has been changed), my initial question was how to get Grunt to compile only one modified file. Using stackoverflow, I was able to answer this question, thanks to everyone :)
But now it seems that the implemented solution disrupts the work with the furnace. When I start with the "grunt server" and display my page in the browser, everything looks great. Then I change one .coffee file and save it. The file compiles (I checked), but my browser never restarts. Only when manually restarting the browser is a new changed code displayed.
So the question is: why cookies don't work anymore?
I don't know if this matters, but the Gruntfile was created using yoman in an older version (with a rough estimate). I updated package.json and Gruntfile to newer specifications using grunt-contrib-watch and buildin livereload. Without grunt.event.on everything works fine.
Sources (partially):
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: '<%= yeoman.app %>/coffeescripts', src: '**/*.coffee', dest: '<%= yeoman.tmp %>/scripts', ext: '.js', options: { runtime: 'inline', sourceMap: true }, } } } }); grunt.event.on('watch', function(action, filepath) { filepath = filepath.replace(grunt.config('coffee.app.cwd')+'/', '' ); grunt.config('coffee.app.src', [filepath]); }); grunt.registerTask('server', function (target) { if (target === 'dist') { return grunt.task.run(['build', 'open', 'connect:dist:keepalive']); } grunt.task.run([ 'clean:server', 'coffee', 'compass:server', 'symlink:bower', 'connect:livereload', 'handlebars', 'notify:watch', 'watch' ]); });
grunt-contrib-watch is used with version v0.4.4 , connect-livereload with version 0.2.0