请原谅我的粗鲁无礼。我已经正确安装了Grun0.4,并且工作正常,我非常喜欢它。
然而,我不明白为什么我的默认任务总是在第一次跳过一些子任务。
下面是Gruntfile的相关部分:
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
copy: {
main: {
files: [
{src: ['src/**'], dest: 'temp/'} // includes files in path and its subdirs
]
}
},
uglify: {
main: {
files: grunt.file.expandMapping(['temp/**/*.js', '!temp/**/*min.js'], './')
}
},
imagemin: {
main: {
files: grunt.file.expandMapping(['temp/**/*.png', 'temp/**/*.jpg'], './')
}
},
compress: {
main: {
options: {
archive: 'archive.zip'
},
files: [
{expand: true, cwd: 'temp/src/', src: ['**'], dest: './'} // makes all src relative to cwd
]
}
},
clean: ["temp", "archive.zip"]
});
// Load the plugins
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-clean');
// Default task(s).
grunt.registerTask('default', ['clean', 'copy', 'uglify', 'imagemin', 'compress']);
grunt.registerTask('test', ['clean', 'copy', 'uglify']);在第一次运行grunt时,uglify和imagemin任务都不处理(和输出)任何东西。如果我再次启动它,一切都会正常工作。如果我手动删除"temp“文件夹并重新启动grunt,uglify和imagemin不会再做任何事情。
请帮我找出我做错了什么。节点版本为0.8.2,gruntcli为0.1.6,grunt为0.4.0
感谢您的阅读
发布于 2013-03-27 18:46:32
原因是grunt.file.expandMapping (在两个任务中使用)是在gruntfile文件加载时运行的,而不是在实际任务运行时运行的。因此,通过其他任务生成的文件将不能用于您的imagemin/uglify-task。
你应该像在其他任务中一样使用文件对象!
https://stackoverflow.com/questions/15103231
复制相似问题