Note that there are some explanatory texts on larger screens.

plurals
  1. POGrunt: Watch multiple files, compile only changed - livereload breaks?
    primarykey
    data
    text
    <p>I am new to Grunt and to Javascript/Coffeescript altogether.</p> <p>We are using Grunt in a rather large project with hundreds of .coffee - files. Since Grunt compiles <em>all</em> coffeefiles (although only one file has changed), my initial question was on how to get Grunt to compile only the one changed file. Using stackoverflow I was able to answer that question, thank you all :)</p> <p>But now it seems that the implemented solution breaks the livereload. When I start with "grunt server" and display my page in the browser, everything looks fine. Then I change one .coffee file and save it. The file gets compiled (I checked), but my browser is never reloaded. Only when I manually reload the browser the new modified code gets displayed.</p> <p>So the question is: Why does livereload no longer work?</p> <p>I don't know if this matters, but the Gruntfile was created with yeoman in an older version (with grunt-regarde). I updated the package.json and the Gruntfile to newer specs using grunt-contrib-watch and the buildin livereload. Without the <code>grunt.event.on</code> everything works fine.</p> <p>Sources (partially):</p> <pre><code>grunt.initConfig({ watch: { coffee: { files: ['&lt;%= yeoman.app %&gt;/coffeescripts/**/*.coffee'], tasks: ['coffee:app'], options: { nospawn: true }, }, compass: { files: ['&lt;%= yeoman.app %&gt;/styles/**/*.{scss,sass}'], tasks: ['compass'] }, templates: { files: ['&lt;%= yeoman.app %&gt;/templates/**/*.tpl'], tasks: ['handlebars'] }, livereload: { options: { livereload: LIVERELOAD_PORT }, files: [ '&lt;%= yeoman.app %&gt;/*.html', '&lt;%= yeoman.tmp %&gt;/styles/**/*.css', '&lt;%= yeoman.tmp %&gt;/scripts/**/*.js', '&lt;%= yeoman.tmp %&gt;/spec/**/*.js', '&lt;%= yeoman.app %&gt;/img/{,*/}*.{png,jpg,jpeg,webp}', ] } }, coffee: { app: { expand: true, cwd: '&lt;%= yeoman.app %&gt;/coffeescripts', src: '**/*.coffee', dest: '&lt;%= yeoman.tmp %&gt;/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' ]); }); </code></pre> <p>grunt-contrib-watch is used with version <code>v0.4.4</code>, connect-livereload with version <code>0.2.0</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload