Gulp Local Service (node Kai Local Service)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.