Continuation gulp Use Getting started three-step compression CSS

Source: Internet
Author: User

Gulp Compression CSS

First, install the GULP-MINIFY-CSS module

Tip: You need to use the command line CD to switch to the corresponding directory after the installation operation.

At the command line, enter

NPM Install Gulp-minify-css

After successful installation you will see the following information: (Installation time may be longer depending on the network)

D:\WAMP\WWW\BOOTSDATATABLE>NPM Install Gulp-minify-css
NPM WARN deprecated [email protected]: use GULP-CLEAN-CSS
[Email protected] D:\wamp\www\BootsDataTable
'---[email protected]
+--[email protected]
| +--[email protected]
| | '---[email protected]
| '---[email protected]
| '---[email protected]
+--[email protected]
'---[email protected]
'---[email protected]
'---[email protected]
'---[email protected]

Second, reference the use of Gulp compression JS to create a gulpfile.js file to write code

Create the Gulpfile.js file in the corresponding directory and write the following:

Get Gulp
var gulp = require (' Gulp ')

Get MINIFY-CSS module (for compressing CSS)
var minifycss = require (' gulp-minify-css ')

Compress CSS Files
Start this task at the command line using gulp CSS
Gulp.task (' CSS ', function () {
1. Find File
GULP.SRC (' Css/*.css ')
2. Compress files
. Pipe (Minifycss ())
3. Save As compressed file
. Pipe (Gulp.dest (' dist/css '))
})

Start this task at the command line using Gulp Auto
Gulp.task (' Auto ', function () {
Listen for file modification, execute CSS task when file is modified
Gulp.watch (' css/*.css ', [' CSS '])
});

Define default tasks using Gulp.task (' default ')
To start a CSS task and auto task at the command line using Gulp
Gulp.task (' Default ', [' css ', ' auto '])


Third, create CSS file

Create the CSS folder in the gulpfile.js corresponding directory and create the A.css file in the css/directory.

/* A.CSS */
Body a{
Color:pink;
}


Four, run Gulp view effect

Enter Gulp + carriage return at command line

Gulp
[10:48:27] Using gulpfile D:\wamp\www\BootsDataTable\gulpfile.js
[10:48:27] starting ' CSS ' ...
[10:48:27] finished ' CSS ' after 3.83 ms
[10:48:27] starting ' auto ' ...
[10:48:27] finished ' auto ' after MS
[10:48:27] starting ' default ' ...
[10:48:27] finished ' default ' after 11μs

Gulp creates the Dist/css directory and creates a a.css file that holds the compressed CSS code. Dist/css/a.css

Continuation gulp Use Getting started three-step compression CSS

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.