咕unt声:Livereload不起作用

汤姆·霍尔斯特斯

每当我尝试使用grunt watch的live reload选项时,我都会遇到这个问题。无论我使用哪个端口,我都会不断收到“致命错误:端口xxxx已被另一个进程使用。” 我列出了所有正在使用的端口,并且选择一个没有出现在列表中的随机数也无济于事:它将xxxx替换为gruntfile中最后使用的端口。

我的gruntfile本身:

module.exports = function (grunt) {

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    watch: {

        options: {
            livereload: true
        },

        js: {
            files: ['.dev/**/*.js'],
            tasks: ['concat', 'uglify', 'watch'],
        },
        scss: {
            files: ['./dev/scss/*.scss'],
            tasks: ['sass', 'concat', 'watch'],
            options: {
                reload: true,
                livereload: false,

            }
        },
        html: {
            files: ['./dev/**/*.html', 'watch'],
            tasks: ['copy', 'watch'],
        },
        grunt: {
            files: ['Gruntfile.js'],
            tasks: ['watch'],
        },
    },

    concat: {
        js: {
            src: ['dev/js/script1.js', 'dev/js/script2.js'],
            dest: 'dev/js/script.js',
        },
        css: {
            src: ['./dev/css/nav.css', './dev/css/anim.css', './dev/css/style.css'],
            dest: './dist/css/style.css',
        },
    },

    uglify: {
        build: {
            src: 'dev/js/script.js',
            dest: 'dist/js/script.min.js'
        }
    },

    sass: {                              // Task
        dev: {                            // Target
            files: {                         // Dictionary of files
                './dev/css/style.css': './dev/scss/style.scss',       // 'destination': 'source'
            },
            tasks: ['copy'],
        }
    },

    copy: {
        main: {
            expand: true,
            cwd: './dev/html',
            src: '*.html',
            dest: './dist/html/'
        },
    },
});

// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-sass');


// Default task(s).
grunt.registerTask('default', ['concat', 'uglify', 'sass', 'copy', 'watch']);

};

我对npm,grunt等仍然不熟悉,并且也使用Yeoman遇到了这个问题。是否有一些应用程序可以自动侦听每个端口(我正在使用Webstorm)?但是,当我关闭它并使用sublime和一个终端时,它一直说每个随机端口都已经在使用中

帕特里克·莫塔德

看起来您正在递归地调用watch ..

以gruntfile的这一部分为例:

watch: { // hey grunt, you now know of a task called 'watch'
    ....
    html: {
        files: ['./dev/**/*.html', 'watch'], // here are the files to watch
        tasks: ['copy', 'watch'], // and oh, hey, when you run watch, make 
                                  // sure to run watch again, recursively, forever
    }

我认为您可以看到进展情况。您的端口正在使用中,因为您的监视任务在尝试再次运行时已经在运行。您无需在手表的每个子部分上将“手表”注册为任务。希望能有所帮助:)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章