zl程序教程

您现在的位置是:首页 >  其他

当前栏目

[Grunt] grunt.initConfig() && grunt.file

amp File grunt
2023-09-14 09:00:56 时间
/**
 * Created by Answer1215 on 9/1/2014.
 */
module.exports = function(grunt){

    grunt.initConfig({
        person: {
            "firstName": "Zhentian"
        }
    })

    grunt.registerTask("default",function(name){
        grunt.log.writeln("Hello Grunt World, welcome: "+grunt.config.get("person").firstName);
    })
}

Type in the Terminal:

grunt

We will get the reuslts:

C:\Users\Answer1215\WebstormProjects\angular\Grunt_Demo>grunt
Running "default" task
Hello Grunt World, welcome: Zhentian

Done, without errors.

 

Also we can use json file to do that:

Create a json file. config.json:

{
    "person":{
        "firstName": "Zhentian Wan"
    }
}

We change the code in GruntFile.js:

module.exports = function(grunt){
/*
    grunt.initConfig({
        person: {
            "firstName": "Zhentian"
        }
    })*/

   grunt.file.defaultEncoding = 'utf8'; grunt.initConfig(grunt.file.readJSON('config.json')); grunt.registerTask("default",function(name){ grunt.log.writeln("Hello Grunt World, welcome: "+grunt.config.get("person").firstName); }) }

type in triminail:

grunt

We will get the result:

C:\Users\Answer1215\WebstormProjects\angular\Grunt_Demo>grunt
Running "default" task
Hello Grunt World, welcome: Zhentian Wan

Done, without errors.

 

Read More about grunt.file: http://gruntjs.com/api/grunt.file