Grunt watch无法重新加载配置文件 - 更改时出错

问题描述 投票:1回答:1

环境是:Linux 2.6.32-573.12.1.el6.x86_64 x86_64,通过SSH

对于我的咕噜声,我有一个略微非标准的设置,详情如下:

/home/scoots/public_html/
    grunt/
        package.json
        node_modules/
        project1/
            Gruntfile.js
        project2/
            Gruntfile.js
    project1/
    project2/

当我开始grunt监视并对我的Gruntfile.js进行更改时(这不是常见的情况,但仍然可能根据项目的需要而发生),我收到以下错误:

$ cd ~/public_html/grunt/project1
$ grunt watch
Running "watch" task
Waiting...

Reloading watch config...
Fatal error: EACCES: permission denied, scandir '/home'

这很简单(只需取消并重启grunt) - 但这需要我注意。我有时可以尝试继续工作,但是现在可以锁定咕噜咕噜的手表。

此外,当我在本地(Windows)计算机上安装了grunt并从Node.js命令提示符运行它时,这段代码常常会起作用。

作为参考,这是一个展示此问题的示例Gruntfile.js:

module.exports = function(grunt) {
    require('time-grunt')(grunt);
    require('jit-grunt')(grunt);
    grunt.file.setBase('../');

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        site_dir: {
            site: '../tcl/wp-content/themes/twentysixteen-child',
            jscache: 'wp-content/themes/twentysixteen-child/js/src',
            grunt: 'tcl'
        },
        watch: {
            css: {
                files: ['<%= site_dir.site %>/css/sass/*.scss'],
                tasks: ['sass', 'postcss'],
                options: {
                    spawn: false
                }
            },
            scripts: {
                files: ['<%= site_dir.site %>/js/src/*.js'],
                tasks: ['include_file', 'uglify'],
                options: {
                    spawn: false
                }
            },
            configFiles: {
                files: ['<%= site_dir.grunt %>/Gruntfile.js'],
                options: {
                    reload: true
                }
            }
        },
        sass: {
            options: {
                style: 'expanded', // compressed in postcss
                sourcemap: true,
                sourceMapEmbed: true,
                precision: 8,
                includePaths: ['node_modules/bootstrap-sass/assets/stylesheets']
            },
            dist: {
                files: {
                    '<%= site_dir.grunt %>/css/layout.css': '<%= site_dir.site %>/css/sass/layout.scss'
                }
            }
        },
        postcss: {
            options: {
                map: {
                    inline: false,
                    annotation: '<%= site_dir.grunt %>/css/maps/'
                },
                processors: [
                    require('autoprefixer')({
                        browsers: [
                          "Android 2.3",
                          "Android >= 4",
                          "Chrome >= 20",
                          "Firefox >= 24",
                          "Explorer >= 8",
                          "iOS >= 6",
                          "Opera >= 12",
                          "Safari >= 6"
                        ]
                    }),
                    require('csswring')()
                ]
            },
            dist: {
                src: '<%= site_dir.grunt %>/css/layout.css',
                dest: '<%= site_dir.site %>/css/layout.min.css'
            }
        },
        include_file: {
            js: {
                cwd: '<%= site_dir.grunt %>/',
                src: [
                    '../<%= site_dir.site %>/js/src/common.js'
                ],
                dest: '<%= site_dir.grunt %>/js/'
            }
        },
        uglify: {
            options: {
                compress: {
                    warnings: true
                },
                mangle: true,
                preserveComments: /(?:^!|@(?:license|preserve|cc_on))/
            },
            build: {
                src: [
                    '<%= site_dir.grunt %>/<%= site_dir.jscache %>/common.js'
                ],
                dest: '<%= site_dir.site %>/js/common.min.js'
            }
        }
    });

    grunt.registerTask('default', ['sass', 'postcss', 'include_file', 'uglify']);
};

和package.json:

{
  "name": "Test",
  "version": "0.1.0",
  "dependencies": {
    "bootstrap-sass": "3.3.7"
  },
  "devDependencies": {
    "autoprefixer": "^6.4.1",
    "csswring": "^5.1.0",
    "grunt": "^1.0.1",
    "grunt-contrib-uglify": "^2.0.0",
    "grunt-contrib-watch": "^1.0.0",
    "grunt-include-file": "^0.1.3",
    "grunt-postcss": "^0.8.0",
    "grunt-sass": "^2.0.0",
    "jit-grunt": "^0.10.0",
    "time-grunt": "^1.4.0"
  }
}

编辑:启用详细/调试:

$ grunt -v -d watch
Initializing
Command-line options: --verbose, --debug=1

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK
Loading "Gruntfile.js" tasks...OK
+ default

Running tasks: watch

Loading "grunt-contrib-watch" plugin

Registering "/home/scoots/public_html/grunt/node_modules/grunt-contrib-watch/tasks" tasks.
Loading "watch.js" tasks...OK
+ watch

Running "watch" task
[D] Task source: /home/scoots/public_html/grunt/node_modules/grunt-contrib-watch/tasks/watch.js
Waiting...
Verifying property watch exists in config...OK
Verifying property watch.css.files exists in config...OK
Verifying property watch.scripts.files exists in config...OK
Verifying property watch.config.files exists in config...OK
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/__bookings.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/__variables.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/_bootstrap-custom.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/_contactform7.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/_lightslider.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/_lity.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/_zoom.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/layout.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/js/src/bootstrap.js for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/js/src/common.js for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/js/src/instafeed.js for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/js/src/lightslider.js for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/js/src/lity.js for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/js/src/scrollreveal.min.js for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/js/src/zoom.js for changes.
Watching tcl/Gruntfile.js for changes.
Watching tcl/css for changes.
Watching tcl/js for changes.
Watching tcl/wp-content for changes.
Clearing require cache for "tcl/Gruntfile.js" file...OK

[[[[I edit the Gruntfile here]]]]

Reloading watch config...
Fatal error: EACCES: permission denied, scandir '/home'
gruntjs grunt-contrib-watch
1个回答
0
投票

文件glob中的前导斜杠有时会导致此错误,但是grunt不会抛出任何错误。这个警告只是一个沉默的失败。

确保您的“文件”配置不会导致此问题,并且此<%= site_dir.site%>模板不会导致null或为空。

watch: {
            css: {
                files: ['<%= site_dir.site %>/css/sass/*.scss'],
                tasks: ['sass', 'postcss'],
                options: {
                    spawn: false
                }
            },
            scripts: {
                files: ['<%= site_dir.site %>/js/src/*.js'],
                tasks: ['include_file', 'uglify'],
                options: {
                    spawn: false
                }
            },
            configFiles: {
                files: ['<%= site_dir.grunt %>/Gruntfile.js'],
                options: {
                    reload: true
                }
            }
        }
© www.soinside.com 2019 - 2024. All rights reserved.