gpt4 book ai didi

gruntjs - 如何在 grunt-watch 任务中忽略一个文件?

转载 作者:行者123 更新时间:2023-12-03 21:01:39 25 4
gpt4 key购买 nike

'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']);
};

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

最佳答案

编辑:

为什么需要将其从 watch 中排除?我在您的 watch:js 任务中看不到任何 glob 模式,该模式会在该文件中寻找更改开始。

原答案:

您是否尝试将 '!public/build.js' 作为监视任务中的最后一个包含?

文档的一部分位于:

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

让我认为开始时排除的文件会以“public/js/**”模式重新添加。

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

js: {
files: ['gruntfile.js', 'server.js', 'app/**/*.js', 'public/js/**', 'test/**/*.js', '!public/build.js'],
tasks: ['uglify', 'jshint'],
options: {
livereload: true,
},
},

关于gruntjs - 如何在 grunt-watch 任务中忽略一个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21237480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com