1. Grunt Effect
Enables repetitive work such as compression, compilation, unit testing, etc.
2, need to install the software
First step: Get Nodejs package from official website, double click to install (under Windows)
Step two: Open cmd command line, execute command ' node-v ', can output version number, indicating node is installed properly
Step three: On the cmd command line, enter the installation command, respectively, to install GRUNT-CLI and grunt
3, Grunt use
First step: Create Package.json and Gruntfile two files in the directory where the project is located
The contents of the Package.json can be customized as:
1 { 2 3 "name": "Project-name", 4 "version": "0.1.0", 5 "Devde Pendencies ": { 6 " grunt ":" ~0.4.5 ", 7 " Grunt-contrib-jshint ":" ~0.10.0 ", 8 "Grunt-contrib-nodeunit": "~0.4.1", 9 "grunt-contrib-uglify": "~0.5.0" } }
Gruntfile content can be customized as follows, modified as appropriate
1Module.exports =function (grunt) {2 3 //Project configuration.4 Grunt.initconfig ({5Pkg:grunt.file.readJSON (' Package.json '),6 uglify: {7 options: {8Banner: '/*! <%= pkg.name%> <%= grunt.template.today ("Yyyy-mm-dd")%> */\n '9},Ten Build: { OneSRC: ' src/<%= pkg.name%>.js ', ADest: ' build/<%=pkg.name%>.min.js ' - } - } the}); - -Load The plugin that provides the "uglify"task. -Grunt.loadnpmtasks (' grunt-contrib-uglify '); + - //Default task (s). +Grunt.registertask (' Default ',[' uglify ']); A at};
4, the configuration file explanation:
About Package.json:
About Gruntfile:
Using Grunt for Web automation