2

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

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

GruntFile.js, package.json, 和server.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文件?

4

1 回答 1

0

包裹解决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可以是任何东西,并且默认使用它,因为它是唯一提供的 uglify 配置文件。如果我提供了多个配置文件,即“test: {}, prod: {}, etc: {}”,那么我将在任务之后以下列方式引用它们:uglify:test, uglify:prod,uglify:etc

于 2014-03-31T16:09:44.827 回答