Gulp.js event stream merge order

前端 未结 4 1798
渐次进展
渐次进展 2021-01-31 09:20

I am trying to merge css and scss files into a main.css file that goes in my build directory. Its working, but not in the right order. The style attributes from the scss files n

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-31 09:49

    It seems that the plugin gulp-order fits perfectly well in your case.

    It allows you to re-order the passed stream with your own glob pattern, for example based on your code :

    return es.merge(cssTomincss, cssFromscss)
        .pipe(order([
          'dev/css/reset.css',
          'dev/css/style.css',
          'dev/css/typography.css',
          'dev/css/sizes.css',
          'dev/css/*.css',
        ]))
        .pipe(concat('main.css'))
        .pipe(minifyCSS())
        .pipe(gulp.dest('build/css'))
    

    One drawback of this is that you have to re-declare your globs, but you can get around by assign your globs to a value and then concat them in you order pipe, much cleaner.

    You may have to set the base option to . of gulp-order as stated in their Readme if the files were not ordered correctly.

    One another way would be to use stream-series, basically the same as event-stream, but the order of your stream is preserved, and you don't have to rewrite your globs.

提交回复
热议问题