2015-10-12 68 views

回答

6

official gulp-ruby-sass documentation認爲它應該這樣做:

var gulp = require('gulp'); 
var sass = require('gulp-ruby-sass');  

gulp.task('sass', function() { 
    return sass('source/file.scss') 
    .on('error', sass.logError) 
    .pipe(gulp.dest('result')); 
}); 
+0

我已經得到了解決,但仍恐怕爲什麼代碼'gulp.src( '上海社會科學院/ app.scss')沒有按'沒有工作。因爲大多數教程都使用此代碼:( 示例:https://www.youtube.com/watch?v = cg7lwX0u-U0,https://www.youtube.com/watch?v=NkomAUQxYr8 – Muhammed

+0

sass函數以不同的方式工作,它需要一個路徑「模式」參數,這就是爲什麼你會得到錯誤的原因 爲什麼不是你的示例代碼爲你工作?你想實現的是什麼不工作爲你提供官方示例? – user1120808

17

吞氣,紅寶石薩斯語法已經改變:

instead of:       it is now: 

gulp.task('styles', function(){  gulp.task('styles', function(){ 
    gulp.src('sass/app.scss')   return 
     .pipe(sass())      sass('sass/app.scss') 
     .pipe(gulp.dest('css/')    .pipe(gulp.dest('css/') 
    ;         ; 
});         }); 

請檢查出來,併爲解決標記您的問題。

+2

好的,如果我想在其他插件之後運行sass,那該怎麼辦呢?所以它不是管道中使用的第一種方法 –

2

Install libsass because it runs much faster than ruby sass , it works with node

npm install gulp-sass --save-dev` 

Install gulp load plugins because it does so much and loads plugins from your json and you dont need to declare in your gulpfile (carefull how many you use because if you load too many it hinders performance)

npm install --save-dev gulp-load-plugins 

var gulp = require('gulp'), 
     $ = require('gulp-load-plugins')({ 
     pattern: ['gulp-*', 'gulp.*'], 
     replaceString: /\bgulp[\-.]/, 
     lazy: true, 
     camelize: true 
     }); 

gulp.task('libsass', function() { 
     gulp.src('sass/app.scss') 
      .pipe($.sass({errLogToConsole: true})) 
      .pipe($.autoprefixer({ 
      browsers: ['last 2 versions'], 
      cascade: false 
      })) 
      .pipe($.sourcemaps.write('app/css/map')) 
      .pipe(gulp.dest('app/css')) 
    });