首页 > 技术文章 > grunt-watch

walle2 2015-10-31 22:22 原文

module.exports = function (grunt){
	// laod all grunt tasks automatically
	require('load-grunt-tasks')(grunt);

	// time how long grunt task take, can help when optimizing build times
	require('time-grunt')(grunt);

	// configure grunt

	grunt.initConfig({
		// the actual grunt server settings
		connect: {
			options: {
				port: 9000,
				hostname: 'localhost',
				//keepalive: true
				livereload: 35729
			},
			all: {
				options: {
					open: true,
					base: ['./'] // index.html directory
				}
			}
		},
		// watch files for changes, and run tasks base on the changed files
		watch: {
			livereload: {
				options: {
					// this port must be same with the connect livereload port
					livereload: '<%= connect.options.livereload %>'
				},
				// watch whatever files you needed.
				files: [
					'./*.html',
					'./app/styles/*.css',
					'./app/js/(,*/)*.js',
					'./app/images/(,*/)*.{png,jpg,gif}'/
				]
			}
		}
	});

	// creates the server task
	grunt.registerTask('serve', ['connect:all', 'watch']);
}

  

推荐阅读