使用gulp / node / libsass进行编译需要30秒以上

时间:2014-11-13 13:51:23

标签: gulp gulp-watch gulp-sass node-sass libsass

我正在使用Gulp和node-sass来编译我的sass。我也在使用node-neat和node-bourbon。但是,当我编译时,需要30-50秒!我究竟做错了什么?我不太确定libsass是如何进入gulp-sass和node-sass的,或者gulp-sass和node-sass之间的区别是什么。在我的gulpfile.js中,我尝试了sass = require('gulp-sass'),sass = require('node-sass'),,但他们给了我相同的结果。另外,我正在使用水管工,如果我有错误就停止观看。这是我的gulpfile.js:

var gulp = require('gulp'),
    sass = require('gulp-sass'),
    bourbon = require('node-bourbon').includePaths;
    neat = require('node-neat').includePaths;
    cache = require('gulp-cache'),
    plumber = require('gulp-plumber'),
    notify = require("gulp-notify"),
    sourcemaps = require('gulp-sourcemaps');

gulp.task('styles', function() {
  return gulp.src('sass/cleverDesign.scss')
    .pipe(plumber())
    .pipe(sourcemaps.init())
    .pipe(sass({
      style: 'expanded',
      includePaths: require('node-bourbon').includePaths,
      includePaths: require('node-neat').includePaths}))
    .pipe(gulp.dest('sass/'))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('sass/' ));
});

// Watch
gulp.task('watch', function() {
  // Watch .scss files
  gulp.watch('sass/**/*.scss', ['styles']);
});

gulp.task('default', ['styles', 'watch']);

1 个答案:

答案 0 :(得分:1)

libSass base> NodeSass(主节点包装器)> Gulp-Sass(gulp友好版)

至于编译时间慢,我会仔细检查你的节点版本,并确保gulp-sass的节点模块是最新版本。一些关键错误已得到修复。

对于管道工问题,可以通过在gulp-sass配置中添加更多行来解决这个问题。 errLogToConsole:true,和.pipe(plumber.stop())

 var gulp = require('gulp'),
    sass = require('gulp-sass'),
    bourbon = require('node-bourbon').includePaths;
    neat = require('node-neat').includePaths;
    cache = require('gulp-cache'),
    plumber = require('gulp-plumber'),
    sourcemaps = require('gulp-sourcemaps');


gulp.task('styles', function() {
  return gulp.src('sass/mainScss.scss')
    .pipe(plumber())
    .pipe(sourcemaps.init())
    .pipe(sass({
      style: 'expanded',
      errLogToConsole: true,
      includePaths: require('node-bourbon').includePaths,
      includePaths: require('node-neat').includePaths}))
    .pipe(gulp.dest('sass/'))
    .pipe(sourcemaps.write())
    .pipe(plumber.stop())
    .pipe(gulp.dest('sass/' ))
});

// Default task
gulp.task('default', function() {
    gulp.start('styles');
});

// Watch
gulp.task('watch', function() {
  gulp.watch('sass/**/*.scss', ['styles']);
});