Grunt Watch致命错误:听EACCES和livereload [英] Grunt Watch Fatal error: listen EACCES and livereload

查看:95
本文介绍了Grunt Watch致命错误:听EACCES和livereload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PC规格:
Windows 7 Enterprise x64



我正在一个项目上运行grunt.js,并且最近开始尝试运行' grunt watch'。



Grunt昨天工作正常,但今天我开始看到:

运行watch任务
等待......致命错误:听EACCES



我在这里读到另一个问题: Cloud 9和Grunt.js



导致我删除'options:{livereload:true}'来自Gruntfile.js



再次运行watch可按预期工作。有没有办法重新配置grunt或livereload以再次使用Grunt进行livereload工作?



另外,只要运行'grunt'命令即可运行所有任务,而不会出错。

谢谢。 / p>

编辑:Gruntfile.js如下:

  module.exports = function (grunt){
grunt.initConfig({
jshint:{
all:['js / src / *。js']
},
uglify:{
选项:{
mangle:{
除外:['jQuery']
},
preserveComments:'none'
},
'js / main.min.js':['js / tmp / debug.js']
},
指南针:{
选项:{
config:'.compass .bb',
sassDir:'sass',
cssDir:'。'
},
my_target:{
}
},
cmq:{
my_target:{
files:{'tmp': ['style.css']}
}
},
cssmin:{
minify:{
keepSpecialComments:0,
expand:true,
cwd:'tmp /',
src:['style.css'],
dest:'。',
ext:'.css'
}
},
imagemin:{
png:{
options:{
optimizationLevel:7
},
files:[{
expand:true,
cwd:'img',
src:['** / *。png'],
dest:'img',
ext:'。 min.png'
}]
},
jpg:{
options:{
progressive:true
},
files:[ {
exp and:true,
cwd:'img',
src:['** / *。jpg'],
dest:'img',
ext:'.min .jpg'
}]
},
gif:{
options:{
progressive:true
},
files:[{
展开:true,
cwd:'img',
src:['** / *。gif'],
dest:'img',
ext :'.min.gif'
}]
}
},
clean:[tmp],
watch:{
scripts:{
文件:'js / src / *。js',
任务:['jshint','concat','uglify','clean'],
选项:{livereload:true }
},
css:{
文件:'sass /*.scss',
任务:['compass','cmq','cssmin','clean'],
options:{livereload:true}
}
},
concat:{
debug:{
src:['js / src / ** / *。js'],
dest:'js / tmp / debug。 js'
}
},
});

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-combine-media-queries');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-imagemin');

grunt.registerTask('default',['jshint','concat','uglify','compass','cmq','cssmin','clean']);


解决方案

重新加载配置为在同一个默认端口上产生的服务器。而不是在您的手表配置中指定 livereload:true 两次,只需配置一次:

  watch:{
options:{livereload:true},
scripts:{
files:'js / src / *。js',
tasks:[' jshint','concat','uglify','clean'],
},
css:{
文件:'sass / *。scss',
tasks:[ 'compass','cmq','cssmin','clean'],
},
},

然后它将只产生1个实时重载服务器。



另一个选项是创建一个专门用于实时重载的监视目标并观察目标文件:

  watch:{
scripts:{
files:'js / src / *。js' ,
任务:['jshint','concat','uglify','clean'],
},
css:{
files:'sass / *。scss ',
任务:['compass','cmq','cssmin','clean'],
},
lr:{
options:{livereload:true},
files:['js / *。js','css / *。css'],
} ,
},


PC Specs: Windows 7 Enterprise x64

I'm running grunt.js on a project and recently started receiving an error when attempting to run 'grunt watch'.

Grunt worked fine yesterday but today I started seeing:

Running "watch" task Waiting...Fatal error: listen EACCES

I read another question here: Cloud 9 and Grunt.js

that lead me to remove 'options: {livereload: true}' from Gruntfile.js

running watch again works as intended. Is there a way to reconfigure grunt or livereload to get livereload working with Grunt again?

Also, just running the command 'grunt' runs all of the tasks without errors.

Thanks.

Edit: Gruntfile.js follows:

module.exports = function(grunt) {
    grunt.initConfig({
        jshint: {
            all: ['js/src/*.js']
        },
        uglify: {
            options: {
                mangle: {
                    except: ['jQuery']
                },
                preserveComments: 'none'
            },
            'js/main.min.js': ['js/tmp/debug.js']
        },
        compass: {
            options: {
                config: '.compass.rb',
                sassDir: 'sass',
                cssDir: '.'
            },
            my_target: {
            }
        },
        cmq: {
            my_target: {
                files: { 'tmp': ['style.css'] }
            }
        },
        cssmin: {
            minify: {
                keepSpecialComments: 0,
                expand: true,
                cwd: 'tmp/',
                src: ['style.css'],
                dest: '.',
                ext: '.css'
            }
        },
        imagemin: {
            png: {
                options: {
                    optimizationLevel: 7
                },
                files: [{
                    expand: true,
                    cwd: 'img',
                    src: ['**/*.png'],
                    dest: 'img',
                    ext: '.min.png'
                }]
            },
            jpg: {
                options: {
                    progressive: true
                },
                files: [{
                    expand: true,
                    cwd: 'img',
                    src: ['**/*.jpg'],
                    dest: 'img',
                    ext: '.min.jpg'
                }]
            },
            gif: {
                options: {
                    progressive: true
                },
                files: [{
                    expand: true,
                    cwd: 'img',
                    src: ['**/*.gif'],
                    dest: 'img',
                    ext: '.min.gif'
                }]
            }
        },
        clean: ["tmp"],
        watch: {
            scripts: {
                files: 'js/src/*.js',
                tasks: ['jshint', 'concat', 'uglify', 'clean'],
                options: { livereload: true }
            },
            css: {
                files: 'sass/*.scss',
                tasks: ['compass', 'cmq', 'cssmin', 'clean'],
                options: { livereload: true }
            }
        },
            concat: {
            debug: {
                src: ['js/src/**/*.js'],
                dest: 'js/tmp/debug.js'
            }
        },
    });

    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-compass');
    grunt.loadNpmTasks('grunt-combine-media-queries');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-imagemin');

    grunt.registerTask('default', ['jshint', 'concat', 'uglify', 'compass', 'cmq', 'cssmin', 'clean']);
}

解决方案

It appears you have 2 live reload servers configured to spawn on the same default port. Instead of specifying livereload: true twice in your watch config, just configure it once:

watch: {
    options: { livereload: true },
    scripts: {
        files: 'js/src/*.js',
        tasks: ['jshint', 'concat', 'uglify', 'clean'],
    },
    css: {
        files: 'sass/*.scss',
        tasks: ['compass', 'cmq', 'cssmin', 'clean'],
    },
},

Then it will only spawn 1 live reload server.

Another option is to create a watch target specifically for live reload and watch your destination files:

watch: {
    scripts: {
        files: 'js/src/*.js',
        tasks: ['jshint', 'concat', 'uglify', 'clean'],
    },
    css: {
        files: 'sass/*.scss',
        tasks: ['compass', 'cmq', 'cssmin', 'clean'],
    },
    lr: {
        options: { livereload: true },
        files: ['js/*.js', 'css/*.css'],
    },
},

这篇关于Grunt Watch致命错误:听EACCES和livereload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆