1. You have to install Node,window under the executable installation package, very simple.
2. Run command: NPM install-g grunt-cli (-G for global installation, can run in any directory) to install the Grunt command-line interface (CLI). Note that installing GRUNT-CLI is not equivalent to installing the Grunt Task Manager. If the installation succeeds, run the command: Grunt-version can see:
3. After entering the project directory, run the command: NPM install Grunt–save-dev installs the latest version of grunt into your project. After the installation is successful, run the command: Grunt-version can see:
4. Create a new Package.json file, as follows
The code is as follows |
Copy Code |
{
"Name": "Grunt",
"Version": "0.1.0″,
"Devdependencies": {
"Grunt": "~0.4.0″,
"Grunt-contrib-jshint": "~0.1.1″,
"Grunt-contrib-nodeunit": "~0.1.2″,
"Grunt-contrib-watch": "~0.2.0″,
"Grunt-contrib-concat": "~0.1.1″,
"Grunt-contrib-uglify": "~0.1.0″,
"Grunt-contrib-cssmin": "~0.9.0″,
"Difflet": "~0.2.3″
}
}
|
5. Run the command at the project root: npm Install, installing some common grunt plug-ins
The code is as follows |
Copy Code |
Module.exports = function (grunt) {
Grunt.initconfig ({
Pkg:grunt.file.readJSON (' Package.json '),
Uglify: {
Options: {
Banner: '/*! <%= pkg.name%> <%= grunt.template.today ("Yyyy-mm-dd")%> */n '
},
Build: {
SRC: ' src/test.js ',
Dest: ' Build/test.min.js '
}
}
});
Load plug-ins that provide "uglify" tasks
Grunt.loadnpmtasks (' grunt-contrib-uglify ');
Default Tasks
Grunt.registertask (' Default ', [' uglify ']);
}
|
7.
9. Run command: Grunt, display as follows:
Default
Done, without errors.