grunt uglify无法在父目录中find我的文件

与我所写的其他所有节点项目不同,这需要节点服务器的文件夹不是root。 这是当前的文件夹层次结构:

- Root/ - build/ - css/ - im/ - js/ - nodeserver/ <-- gruntfile and package are here 

GruntFile.jspackage.jsonserver.js都位于nodeserver/

这是我的GruntFile:

 module.exports = function(grunt) { // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { files: { '../build/all.min.js':['../js/config.js'] }, options: { banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n', report: true } } }); // Load the plugin that provides the "uglify" task. grunt.loadNpmTasks('grunt-contrib-uglify'); // Default task(s). grunt.registerTask('default', ['uglify']); }; 

当我运行grunt时,它找不到我指定的文件。 这是回应:

 Running "uglify:files" (uglify) task ------------------------------------ Verifying property uglify.files exists in config...OK File: [no files] Options: banner="/*! demo-webservice 2014-03-28 */\n", footer="", compress={"warnings":false}, mangle={}, beautify=false, report 

为什么不能看到我的js文件?

包装files: {} my_target: {}解决了我的问题。

 grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { my_target: { files: { '../build/all.min.js':['../js/config.js'] } }, options: { banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n', report: true } } }); 

^ — initConfig的新版本。

还应该注意的是, my_target可以是任何东西,默认情况下使用,因为它是唯一提供的uglifyconfiguration文件。 如果我提供了多个configuration文件,即“test:{},prod:{},etc:{}”,那么我将在以下方式之后引用它们: uglify:test uglify:produglify:etc