SASS进口商不和gulp-ruby-sass合作

时间:2014-02-04 16:40:47

标签: sass gruntjs gulp

我尝试设置一个描述为here的项目。一切正常,但SASS导入不起作用。

main.scss

@import
  "partials/0.mixins",
  "partials/1.settings",
  "partials/2.normalize",
  "partials/3.base",
  "partials/4.layout",
  "partials/5.typo",
  "partials/6.states",
  "partials/7.theme",
  "partials/8.print";

gulp 会产生以下 main.css

@import
  "partials/0.mixins",
  "partials/1.settings",
  "partials/2.normalize",
  "partials/3.base",
  "partials/4.layout",
  "partials/5.typo",
  "partials/6.states",
  "partials/7.theme",
  "partials/8.print";

main.min.css 为空。我试图在我的gulpfile.js中使用loadPath标志但没有成功;(我的任务配置:

...
// Styles
gulp.task('styles', function() {
  return gulp.src('src/styles/main.scss')
    .pipe(sass({
        check: true,
        loadPath: 'src/styles',
        style: 'expanded'
    }))
    .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
    .pipe(gulp.dest('dist/styles'))
    .pipe(rename({ suffix: '.min' }))
    .pipe(minifycss())
    .pipe(livereload(server))
    .pipe(gulp.dest('dist/styles'))
    .pipe(notify({ message: 'Styles task complete' }));
});
...

我的资源来自Compass / SASS项目,并且grunt可以使用。

有什么建议吗?

谢谢&再见 拉尔夫

2 个答案:

答案 0 :(得分:2)

您正在传递选项check: trueas the documentation states告诉任务“只检查语法,不评估”。试一试,不要check: true

答案 1 :(得分:0)

感谢Brian的提示。使用 gulp-compass 可以。

这是我的 gulpfile.js

// Load plugins
var gulp = require('gulp'),
    compass = require('gulp-compass'),
    autoprefixer = require('gulp-autoprefixer'),
    minifycss = require('gulp-minify-css'),
    jshint = require('gulp-jshint'),
    uglify = require('gulp-uglify'),
    imagemin = require('gulp-imagemin'),
    rename = require('gulp-rename'),
    clean = require('gulp-clean'),
    concat = require('gulp-concat'),
    notify = require('gulp-notify'),
    cache = require('gulp-cache'),
    livereload = require('gulp-livereload'),
    lr = require('tiny-lr'),
    server = lr();

// Styles
gulp.task('styles', function() {
  return gulp.src('src/styles/main.scss')
    .pipe(compass({
        sass: 'src/styles',
        css: 'dist/styles'
    }))
    .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
    .pipe(gulp.dest('dist/styles'))
    .pipe(rename({ suffix: '.min' }))
    .pipe(minifycss())
    .pipe(livereload(server))
    .pipe(gulp.dest('dist/styles'))
    .pipe(notify({ message: 'Styles task complete' }));
});

// Scripts
gulp.task('scripts', function() {
  return gulp.src('src/scripts/**/*.js')
    .pipe(jshint('.jshintrc'))
    .pipe(jshint.reporter('default'))
    .pipe(concat('main.js'))
    .pipe(gulp.dest('dist/scripts'))
    .pipe(rename({ suffix: '.min' }))
    .pipe(uglify())
    .pipe(livereload(server))
    .pipe(gulp.dest('dist/scripts'))
    .pipe(notify({ message: 'Scripts task complete' }));
});

// Images
gulp.task('images', function() {
  return gulp.src('src/images/**/*')
    .pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
    .pipe(livereload(server))
    .pipe(gulp.dest('dist/images'))
    .pipe(notify({ message: 'Images task complete' }));
});

// Clean
gulp.task('clean', function() {
  return gulp.src(['dist/styles', 'dist/scripts', 'dist/images'], {read: false})
    .pipe(clean());
});

// Default task
gulp.task('default', ['clean'], function() {
    gulp.start('styles', 'scripts', 'images');
});

// Watch
gulp.task('watch', function() {

  // Listen on port 35729
  server.listen(35729, function (err) {
    if (err) {
      return console.log(err);
    }

    // Watch .scss files
    gulp.watch('src/styles/**/*.scss', ['styles']);

    // Watch .js files
    gulp.watch('src/scripts/**/*.js', ['scripts']);

    // Watch image files
    gulp.watch('src/images/**/*', ['images']);

  });

});

非常感谢。

侨 拉尔夫