Compiling SASS and SUSY with GULP

2019-04-02 05:02发布

I am trying to get gulp to compile my sass and use the susy grid/framework.

I'm having troubles finding any information about this online.

I have included:

"gulp-ruby-sass": "^0.7.1",

into my package.json and installed everything.

My gulp sass gulp task likes like so:

gulp.task('sass', ['images'], function () {
  return gulp.src('src/sass/*.{sass, scss}')
    .pipe(sass({
      bundleExec: true,
      sourcemap: true,
      sourcemapPath: '../sass'
    }))
    .on('error', handleErrors)
    .pipe(gulp.dest('build'));
});

So I can't for the life of me work out how to include susy so it complies using gulp, I haven't looked and can't seem to find anything relating to this online.

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-04-02 05:24

You can use gulp-compass, you only need to have compass installed in your system and install gulp-compass package through npm, here is a sample code:

var compass = require('gulp-compass');

gulp.task('compass', function() {
  return gulp.src('./src/*.scss')
  .pipe(compass({
    // Gulp-compass options and paths
    css: 'app/assets/css',
    sass: 'app/assets/sass',
    require: ['susy']
  }))
  .on('error', handleErrors)
  .pipe(gulp.dest('app/assets/temp'));
});

More info about this package here

查看更多
不美不萌又怎样
3楼-- · 2019-04-02 05:34

To have more details from Jamie's answer, here is what you can do to use susy without compass..

  1. download .zip package of susy from github. extract package into node_modules directory.
  2. In my case I put it in susy-master folder.
  3. In gulpfile.js, you could have some thing like this to include susy package. Note that the important is to put correct includePath value to be the same path of the susy-master folder..

    gulp.task('sass', function(){
      gulp.src('public/sass/styles.scss')
        .pipe(sourcemaps.init())
        .pipe(sass({
            outputStyle: 'compressed',
            includePaths: ['node_modules/susy-master/sass']
        }).on('error', sass.logError))
    
        .pipe(sourcemaps.write('maps'))
        .pipe(gulp.dest('public/css'))
    });
    
  4. Import susy in styles.scss

    @import "susy";
    
查看更多
登录 后发表回答