简体   繁体   English

如何在Gulp.js任务中添加CSS文件?

[英]How can I add CSS file in the middle of Gulp.js task?

How can I add CSS file in the middle of a pipe? 如何在管道中间添加CSS文件?

 gulp.task('css', function () { var processors = [ // list of PostCSS plugins ]; return gulp.src('src/css/style.css') // Add style.css .pipe(postcss(processors)) // Use PostCSS .pipe(uncss({ html: ['dist/index.html'] // Remove unused selectors })) // And here I want to add some other CSS file .pipe(nano()) // Minify CSS .pipe(gulp.dest('dist/css/')); }); 

Gulp-add-src not works with CSS files. Gulp-add-src不适用于CSS文件。 .pipe(gulp.src('src/css/other.css')) -> also not works .pipe(gulp.src('src / css / other.css')) - >也行不通

How can I solve this problem? 我怎么解决这个问题?

You should use merge-streams if you would like to use multiple srcs or need to merge different formats such as less, scss, css into a single minified css file, like in this example: 如果您想使用多个srcs或需要将不同的格式(如less,scss,css)合并到一个缩小的css文件中,则应使用merge-streams,如下例所示:

gulp.task('build/admin', function() {

    var lessStream = gulp.src([...])
        .pipe(less())
        .pipe(concat('less-files.less'))
    ;

    var scssStream = gulp.src([...])
        .pipe(sass())
        .pipe(concat('scss-files.scss'))
    ;

    var cssStream = gulp.src([...])
        .pipe(concat('css-files.css'))
    ;

    var mergedStream = merge(lessStream, scssStream, cssStream)
        .pipe(concat('styles.css'))
        .pipe(minify())
        .pipe(gulp.dest('web/css'));

    return mergedStream;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM