Gulp is a very useful Web front-end automation development tool that can help us do a lot of work by configuring the Gulp task. Not only that, we can also use Gulp to build a simple server for us to test. Let's look at how to configure:
1. First, create Package.json files (package dependencies)
NPM Init
It will then appear as follows (if you don't fill in anything, press ENTER directly until Yes is confirmed and you can modify the file later)
2. Install Gulp NPM i-d Gulp
NPM i-d Gulp-connect
i-d equal to--save-dev
3. Create a new Gulpfile.js file and edit (copy below)
var gulp = require (' gulp ');
var connect = require (' Gulp-connect ');
Gulp.tack (' webserver ', function () {
Connect.server ({
Livereload:true,
port:2333
});
});
Gulp.tack (' Default ', [' webserver ']);
4. Enter gulp at the command line, then you can access localhost:2333 in the browser, at which point the file structure is as follows:
5. Access via mobile phone
1 The first computer to open WiFi, mobile phone connected to the computer WiFi
2 Open the command line (win+r, enter cmd)
3) Input Command ipconfig
4 Remember IPv4 address (if it is 192.110.16.1), enter 192.110.16.1:2333 in the mobile browser
5 Point Open demo.html You can test your page on the phone
Other
Usually also use Gulp to perform other tasks, such as compiling sass,less, compressing JS files, etc.
varGulp =require(' Gulp '), connect =require(' Gulp-connect '), uglify =require(' gulp-uglify '), Sass =require(' Gulp-ruby-sass '), Autoprefixer =require(' Gulp-autoprefixer '); Gulp.task (' webserver ',function() {Connect.server ({Livereload:true,Port: 2333});
}); Gulp.task (' script ',function() {GULP.SRC (' Js/*.js '). Pipe (Uglify ()). Pipe (Gulp.dest (' Dist/js '));
}); Gulp.task (' Sass ',function() { returnSass' Sass/*.scss '). On (' ERROR ',function(ERR) {Console. Error (' sasserror! 'Err. Message); }). Pipe (Gulp.dest (' Dist/css '));
}); Gulp.task (' Auto ',function() {Gulp.watch (' Js/*.js ', [' script ']); Gulp.watch (' Sass/**/*.scss ', [' Sass ']);
}); Gulp.task (' Default ', [' webserver ',' Sass ',' script ',' Auto ']);
--------------------------I am a split line (with Ndoejs)----------------------(1) After installing node, open cmd to enter NPM install Anywhere-g Install Anywhere (2) on the CMD page, locate the path where you want to build the server, and then enter the current path: Anywhere 8860