Gruntjs 如何在grunt监视任务中忽略一个文件?

Gruntjs 如何在grunt监视任务中忽略一个文件?,gruntjs,grunt-contrib-watch,Gruntjs,Grunt Contrib Watch,我试图排除public/build.js文件,但它似乎不起作用。我做错了什么?添加到文件名的开头!public/build.js 您还可以添加一个jshintignore文件,其中包含所有要忽略的文件。编辑: 你为什么要把它从手表中排除?在您的watch:js任务中,我没有看到任何glob模式会首先在该文件中查找更改 原始答复: 你试过搬家吗!public/build.js作为监视任务中的最后一个包含项 文档的一部分位于: 模式按顺序处理,带有!-前缀的匹配项从结果集中排除匹配的文件 让我觉得,

我试图排除
public/build.js
文件,但它似乎不起作用。我做错了什么?

添加
到文件名的开头<代码>!public/build.js

您还可以添加一个jshintignore文件,其中包含所有要忽略的文件。

编辑:

你为什么要把它从手表中排除?在您的watch:js任务中,我没有看到任何glob模式会首先在该文件中查找更改

原始答复:

你试过搬家吗!public/build.js作为监视任务中的最后一个包含项

文档的一部分位于:

模式按顺序处理,带有!-前缀的匹配项从结果集中排除匹配的文件

让我觉得,开始时被排除的文件会以“public/js/**”模式重新添加

我会尝试将您的js watch任务更改为此

'use strict';

module.exports = function(grunt) {
    // Project Configuration
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        watch: {
            jade: {
                files: ['app/views/**'],
                options: {
                    livereload: true,
                },
            },
            js: {
                files: ['!public/build.js', 'gruntfile.js', 'server.js', 'app/**/*.js', 'public/js/**', 'test/**/*.js'],
                tasks: ['uglify', 'jshint'],
                options: {
                    livereload: true,
                },
            },
            html: {
                files: ['public/views/**'],
                options: {
                    livereload: true,
                },
            },
            css: {
                files: ['public/css/**'],
                options: {
                    livereload: true
                }
            }
        },
        jshint: {
            all: {
                src: ['!public/build.js', 'gruntfile.js', 'server.js', 'app/**/*.js', 'public/js/**', 'test/**/*.js'],
                options: {
                    jshintrc: true
                }
            }
        },
        uglify: {
            options: {
                mangle: false
            },
            dist: {
                files: {
                    'public/build.js': ['public/js/**/*.js']
                }
            }
        },
        nodemon: {
            dev: {
                options: {
                    file: 'server.js',
                    args: [],
                    ignoredFiles: ['public/**'],
                    watchedExtensions: ['js'],
                    nodeArgs: ['--debug'],
                    delayTime: 1,
                    env: {
                        PORT: 3000
                    },
                    cwd: __dirname
                }
            }
        },
        concurrent: {
            tasks: ['nodemon', 'watch', 'uglify'],
            options: {
                logConcurrentOutput: true
            }
        },
        mochaTest: {
            options: {
                reporter: 'spec',
                require: 'server.js'
            },
            src: ['test/mocha/**/*.js']
        },
        env: {
            test: {
                NODE_ENV: 'test'
            }
        },
        karma: {
            unit: {
                configFile: 'test/karma/karma.conf.js'
            }
        }
    });

    //Load NPM tasks 
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-mocha-test');
    grunt.loadNpmTasks('grunt-karma');
    grunt.loadNpmTasks('grunt-nodemon');
    grunt.loadNpmTasks('grunt-concurrent');
    grunt.loadNpmTasks('grunt-env');

    //Making grunt default to force in order not to break the project.
    grunt.option('force', true);

    //Default task(s).
    grunt.registerTask('default', ['jshint', 'concurrent']);

    //Test task.
    grunt.registerTask('test', ['env:test', 'mochaTest', 'karma:unit']);
};
js: {
  files: ['gruntfile.js', 'server.js', 'app/**/*.js', 'public/js/**', 'test/**/*.js', '!public/build.js'],
  tasks: ['uglify', 'jshint'],
  options: {
    livereload: true,
  },
},