为什么我在grunt watch任务中的重新加载无法正常工作

时间:2016-03-23 10:37:12

标签: javascript node.js gruntjs watch livereload

这是我的代码。当html / css / js发生变化时,我将监视任务设置为livereload。我使用了来自另一个项目的grunt文件来创建这个文件,到目前为止它看起来完全相同。我不知道我能做些什么才能让它再次发挥作用,所以任何建议都值得赞赏。

'use strict'
module.exports = function(grunt) {
	grunt.initConfig({
		pkg: grunt.file.readJSON('package.json'),

		connect: {
			server: {
                options: {
                    port: 6001,
                    base: './',
                    livereload: false,
                    open: {
                        target: 'http://localhost:6001'
                    }
                }
            }
		},

		watch: {
			options: {
                livereload: true
            },
			html: {
				files: ['index.html', 'src/html/*.html'],
				tasks: ['htmlhint'],
			},
			sass: {
				files: ['src/sass/**/*.scss'],
				tasks: ['sass', 'cssmin'],
			},
			js: {
				files: ['src/js/**/*.js'],
				tasks: ['jshint', 'uglify'],
			}
		},

		copy: {
      		build: {
		        cwd: 'src/',
		        src: ['**/*.html'],
		        dest: 'build/html',
		        expand: true,
		        
      		},
      		index: {
      			src: ['index.html'],
      			dest: 'build/html',
      			expand: true
      		}

    	},

    	clean: {
    		build: {
                src: ['build/**/'] // Destination Folder
            }
        },
	});

	grunt.loadNpmTasks('grunt-contrib-uglify');
	grunt.loadNpmTasks('grunt-contrib-sass');
	grunt.loadNpmTasks('grunt-contrib-cssmin');
	grunt.loadNpmTasks('grunt-contrib-connect');
	grunt.loadNpmTasks('grunt-contrib-jshint');
	grunt.loadNpmTasks('grunt-htmlhint');
	grunt.loadNpmTasks('grunt-contrib-watch');
	grunt.loadNpmTasks('grunt-contrib-copy');
	grunt.loadNpmTasks('grunt-contrib-clean');

	grunt.registerTask('default', ['clean', 'copy', 'sass', 'cssmin', 'jshint', 'uglify', 'htmlhint', 'connect', 'watch']);
	grunt.registerTask('build', ['clean']);
    grunt.registerTask('conn', ['connect']);
    grunt.registerTask('css', ['sass', 'cssmin']);
    grunt.registerTask('html', ['htmlhint']);
    grunt.registerTask('js', ['jshint', 'uglify']);
    grunt.registerTask('production', ['build', 'css', 'js', 'html', 'connect']);
    grunt.registerTask('serve', ['connect', 'watch']);
};
<script src="//localhost:35729/livereload.js"></script>

这有些不起作用。它与港口有关吗?或者它可能与我的咕噜声任务有关?

0 个答案:

没有答案