Skip to content

Instantly share code, notes, and snippets.

@makotot
Last active December 19, 2015 13:49
Show Gist options
  • Save makotot/5964920 to your computer and use it in GitHub Desktop.
Save makotot/5964920 to your computer and use it in GitHub Desktop.
grunt-contrib-watchでlivereload
module.exports = function (grunt) {
'use strict';
// grunt-contrib-watchのlivereloadオプションでlivereload
grunt.initConfig({
watch: {
html: {
files: '**/*.html',
tasks: [],
options: {
livereload: true,
nospawn: true
}
},
less: {
files: ['./css/less/*'],
tasks: ['less'],
options: {
livereload: true,
nospawn: true
}
},
js: {
files: 'js/*.js',
tasks: ['jshint'],
options: {
livereload: true,
nospawn: true
}
}
},
connect: {
livereload: {
options: {
port: 9001,
hostname: '0.0.0.0',
base: './',
middleware: function (connect, options) {
return [
require('connect-livereload')(),
connect.static(options.base),
connect.directory(options.base)
];
}
}
}
},
jshint: {
files: {
src: ['js/*.js']
},
options: {
eqeqeq: true,
globals: {
jQuery: true
}
}
},
less: {
development: {
options: {
compress: true,
yuicomepress: true
},
files: {
'css/common.css': 'css/less/common.less'
}
}
}
});
grunt.event.on('watch', function (action, filepath) {
grunt.log.write(action, filepath);
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.registerTask('default', ['connect', 'watch']);
};
{
"name": "",
"version": "0.0.1",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.6.2",
"grunt-contrib-watch": "~0.5.1",
"grunt-contrib-less": "~0.6.4",
"grunt-contrib-connect": "~0.3.0",
"connect-livereload": "~0.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment