klei/gulp-inject

Create scss imports with gulp-inject- Guide

jenstornell opened this issue · 1 comments

Here is how to use gulp-inject to populate a file with @import rows. That can be done to have a import.scss file to use with gulp-sass.

The benefit against gulp-glob-sass and gulp-concat is that Scss mixins can be used without any trouble and without any hacks.

The only downside would be that you need to run gulp imports after you have created a new scss file (not when you update them).

function import_scss() {
  return gulp
    .src('assets/css/imports.scss')
    .pipe(
      inject(
	gulp.src([ 'custom/components/global/reset.scss', 'custom/components/**/*.scss' ], {
	  read: false
	}),
	{
	  starttag: '/* inject:imports */',
	  endtag: '/* endinject */',
	  transform: function(filepath) {
	    return '@import ".' + filepath + '";';
	  }
	}
      )
    )
    .pipe(gulp.dest('assets/css'));
}

exports.imports = import_scss;

To run do it like this:

gulp imports
rejas commented

Thx for the info. Would you like to do a PR to add this to the README?