user5460152
user5460152

Reputation:

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?

Upvotes: 3

Views: 3283

Answers (1)

Yoan
Yoan

Reputation: 2197

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

Upvotes: 9

Related Questions