Environment
Installing Gulp and Grunt is all about node's package management tool-NPM, so you'll need to install node on your computer so you can install Gulp and Grunt. (Install node automatically installs NPM, detects installation success Node-v, NPM-V)
Installation
To use Gulp in your project, you need to install the GULP command-line tool in the global scope first, then install the Gulp in the project. (If you encounter permission problems, add sudo before the command)
Install -G gulp
Go into the project and install the Gulp.
Install Gulp
Then enter NPM init to create a Package.json file for the project, so that the gulp as a project development dependency, put into this Package.json file
NPM Init
Use of Gulp
Module Installation (--save-dev means to rely on the module as the development of the project, put it in the Package.json file. )
Install module name --save-dev
Task Creation
varGulp = require (' gulp ');//let the gulp variable have all the Gulp methods, create gulp tasks, and use the Gulp task method varUglify = require (' gulp-uglify ');//Compression JS varRename = require (' Gulp-rename ');//renaming //Create a taskGulp.task (' A ',function() { returnGULP.SRC (' Src/main.js '). Pipe (Uglify ())// Piping Pipe. Pipe (Gulp.dest (' dest ')); }); //Create a B taskGulp.task ("B",function(){ returnGULP.SRC ("Src/main.js"). Pipe (Rename ("A.min.js"). Pipe (Gulp.dest ("Dest"));//Direct Write output directory //. Pipe (Gulp.dest ("dest/a.min.js")); Error }); Gulp.task (' Default ', [' A ', ' B ']);
task Execution (need to go to the directory where the project is executed)
The greet here is the task name, a is a task, B is the B task, and default is all tasks in []
Gulp A
3. Gulp Installation and use