zl程序教程

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

当前栏目

[Grunt] Install grunt and test. 1

and install test grunt
2023-09-14 08:59:21 时间

1. Using cmd to type:

npm install -g grunt-cli
npm install grunt

 

2. Create a GruntFile.js in the project dir.

 

3. Write code into the grunt file:

/**
 * Created by Answer1215 on 9/1/2014.
 */
module.exports = function(grunt){
    grunt.registerTask("default",function(){
        grunt.log.writeln("Hello Grunt World");
    })
}

 

4. In the Terminal, type:

grunt default

we will get the result:

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

Done, without errors.

 

5. Grunt can accpet parameter:

/**
 * Created by Answer1215 on 9/1/2014.
 */
module.exports = function(grunt){
    grunt.registerTask("default",function(name){
        grunt.log.writeln("Hello Grunt World, welcome: "+name);
    })
}

 

6. Type in termianl:

grunt default:"Zhentian Wan"

we will get the result:

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

Done, without errors.