我对节点使用 Grunt 和一堆软件包。例如 jsHint , jsDoc , Browserify , Uglify ...
我运行 Gruntfile 与 Watchify 和更新进行自动化。到目前为止,非常好。
Gruntfile,完全正常工作:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
all: ['my/js/files/*.js']
},
jsdoc : {
dist : {
src: ['my/js/files/*.js'],
options: {
destination: 'doc'
}
}
},
browserify: {
'public/js/files/script.js': ['my/js/files/*.js']
},
uglify: {
my_target: {
files: {
'public/js/files/script.js': ['public/js/files/script.js']
}
}
},
htmlmin: {
dist: {
files: {
'public/html/index.html': ['public/html/index.html']
}
}
},
cssmin: {
combine: {
files: {
'public/css/css.min.css': ['my/css/files/*.css']
}
}
},
watch: {
javascript: {
files: ['my/js/files/*.js'],
tasks: ['newer:jshint:all', 'jsdoc', 'browserify', 'uglify']
},
html: {
files: ['public/html/index.html'],
tasks: ['htmlmin']
},
css: {
files: ['public/css/*.css'],
tasks: ['cssmin']
}
}
});
// load plugins
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-newer');
};
只要我只使用更新 jsHint ,它就可以使用。但如果我尝试使用 jsDoc 或 Uglify ,我会收到错误消息。
示例:
我试试这个......
tasks: ['newer:jshint:all', 'newer:jsdoc:all', 'browserify', 'uglify']
而不是......
tasks: ['newer:jshint:all', 'jsdoc', 'browserify', 'uglify']
我收到错误消息:
Running "newer:jsdoc:all" (newer) task
Warning: Cannot read property 'files' of undefined Use --force to continue.
Aborted due to warnings.
为什么它适用于jsHint而不适用于其他?有人有想法吗?非常感谢一些提示!
亲切的问候
答案 0 :(得分:2)
jshint任务的目标是all
,因此newer:jshint:all
是正确的。
您的jsdoc目标是dist
,因此您必须使用此目标:newer:jsdoc:dist
对你而言更容易,每个任务只有一个目标(只有你的监视任务有多个目标)所以你只能这样做:
['newer:jshint', 'newer:jsdoc', 'browserify', 'uglify']