I have a bunch of Stylus files in './styles/stylus/**.styl'
and a bunch of CSS files in './styles/css/**.css'
.
How do I use Gulp to compile the Stylus files, concat the result with all of the CSS files and output it to './styles/out.css'
?
I have a bunch of Stylus files in './styles/stylus/**.styl'
and a bunch of CSS files in './styles/css/**.css'
.
How do I use Gulp to compile the Stylus files, concat the result with all of the CSS files and output it to './styles/out.css'
?
You can use gulp-filter like:
var gulp = require('gulp');
var stylus = require('gulp-stylus');
var concat = require('gulp-concat');
var Filter = require('gulp-filter');
gulp.task('css', function () {
var filter = Filter('**/*.styl', { restore: true });
return gulp.src([
'./styles/stylus/**.styl',
'./styles/css/**.css'
])
.pipe(filter)
.pipe(stylus())
.pipe(filter.restore)
.pipe(concat('out.css'))
.pipe(gulp.dest('./styles'));
});
You should be able to create two separate streams of files and merge them with event-stream
:
var es = require('event-stream');
gulp.task('styles', function() {
var stylusStream = gulp.src('./styles/stylus/**.styl')
.pipe(stylus());
return es.merge(stylusStream, gulp.src('./styles/css/**.css'))
.pipe(concat('out.css'))
.pipe(gulp.dest('./styles'));
});
Within your Stylus files, you can just @require
CSS files:
@require 'something.css'
Then there’s no need for concatenation or any other complexity in Gulp, and your file load order is set explicitly within the .styl files.
I just found a great solution to this: use @require for each of the other .styl files in your main.styl file, and just watch gulp.src('src/css/main.styl')
© 2022 - 2024 — McMap. All rights reserved.
@require legacy/*
won't work since the globbing import works only for .styl source files. – Congruous