简体   繁体   中英

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?

 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. .pipe(gulp.src('src/css/other.css')) -> also not works

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:

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;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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