I'm trying to configure grunt to livereload js and less/css files on changes. While grunt does correctly "watch" and execute assigned tasks, it does not livereload the files. Below is my configuration, does anyone see what is wrong?
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
jshint: {
files: ["Gruntfile.js", "src/javascripts/**/*.js"],
options: {
globals: {
jQuery: true,
console: true,
module: true
}
}
},
concat: {
options: {
stripBanners: true,
banner: "/*! <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today('yyyy-mm-dd') %> */\n",
separator: "\n"
},
js: {
src: ["src/javascripts/main.js", "src/javascripts/**/*.js"],
dest: "../app/assets/javascripts/application.js"
},
less: {
src: ["src/stylesheets/**/*.less"],
dest: "../app/assets/stylesheets/application.less"
}
},
watch: {
js: {
files: ["<%= jshint.files %>"],
tasks: ["jshint", "concat:js"],
options: {
livereload: true
}
},
less: {
files: ["<%= concat.less.src %>"],
tasks: ["concat:less"],
options: {
livereload: true
}
}
}
});
grunt.loadNpmTasks("grunt-contrib");
grunt.registerTask("default", ["jshint", "concat"]);
};
Note: I have included the following script tag within the html head tag.
<script src="http://localhost:35729/livereload.js"></script>
GitHub - gruntjs/grunt-contrib-watch: Run tasks whenever watched files change.
Tasks are grunt's bread and butter. The stuff you do most often, like jshint or nodeunit . Every time Grunt is run, you specify one or more tasks to run, which tells Grunt what you'd like it to do. If you don't specify a task, but a task named "default" has been defined, that task will run (unsurprisingly) by default.
Grunt is a JavaScript task runner, a tool used to automatically perform frequent tasks such as minification, compilation, unit testing, and linting. It uses a command-line interface to run custom tasks defined in a file (known as a Gruntfile). Grunt was created by Ben Alman and is written in Node. js.
Your config is trying to start 2 live reload servers on the same port. If you would like 1 live reload server to trigger on all your watch targets then just add 1 livereload option at the task level:
watch: {
options: {
livereload: true
},
js: {
files: ["<%= jshint.files %>"],
tasks: ["jshint", "concat:js"],
},
less: {
files: ["<%= concat.less.src %>"],
tasks: ["concat:less"],
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With