189.gulp create css file processing task

In the cmd window execute the command: npm install gulp-cssnano, the plug-in is a package npm management, in fact, the equivalent of Python npm in the pip, pip is a Python package management tool, but npm package management tool that node.

Css files for processing, the main is to compress the files, css files are compressed to just rely gulp package or can not be, the same need for a gulp of plug-in, gulp-cssnano, the plug-in can be css file compression processing.

Specific examples of code is as follows:

var gulp = require('gulp');
var cssnano = require('gulp-cssnano');

//创建一个名为css的任务,赋予该任务一个匿名函数
gulp.task('css', function() {
    //将源文件在/js/所有js文件进行以下相关处理
    gulp.src('./css/*.css')
    //将源文件通过pip流传送给cssnano这个处理器
    .pipe(cssnano())
    //将处理过的文件放到目的文件夹中,这就使用到了gulp内置的函数gulp.dest(),可以将文件放到目的地
    .pipe(gulp.dest('./dist/css/'))
});

Guess you like

Origin www.cnblogs.com/guyan-2020/p/12387330.html
Recommended