使用.pipe时的gulp-ruby-sass TypeError(sass({style:'expanded'))

时间:2014-12-22 08:36:04

标签: gulp

行。我在使用此代码时遇到问题。我之前使用过gulp-ruby-sass,但直到现在我还没有遇到过这种错误。我正在使用gulp-ruby-sass 1.0.0。我只是想尝试使用gulp-ruby-sass在css中运行我的sass文件。但是,这显然不起作用。任何建议将不胜感激。

这是错误:

 TypeError: string is not a function
    at Gulp.<anonymous> (/Users/xxxxxxxxxxx/xxxx/xxxxxxx/gulpfile.js:22:15)
    at module.exports (/Users/xxxxxxxxxxx/xxxx/xxxxxxxx/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/Users/xxxxxxxxxxx/xxxx/xxxxxxx/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/Users/xxxxxxxxxxx/xxxx/xxxxxxx/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/Users/xxxxxxxxxxx/xxxx/xxxxxxx/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
    at /usr/local/lib/node_modules/gulp/bin/gulp.js:129:20
    at process._tickCallback (node.js:442:13)
    at Function.Module.runMain (module.js:499:11)
    at startup (node.js:119:16)
    at node.js:929:3

我正在为我的项目使用的Gulp代码如下:

var gulp = require('gulp'),
    sass = ('gulp-ruby-sass'),
    uglify = require('gulp-uglify'),
    livereload = require('gulp-livereload'),
    plumber = require('gulp-plumber'),
    jshint = require('gulp-jshint');

var paths = {
    sass: 'stylesheets/scss/',
    css: 'stylesheets/css'
    };

gulp.task('lint', function() {
    return gulp.src('angular/app.js')
        .pipe(jshint())
        .pipe(jshint.reporter());
    });

gulp.task('sass', function() {
    return gulp.src(paths.sass + '*.scss')
        .pipe(plumber())
        .pipe(sass({style: 'expanded'})) // HERE IS WHERE THE ERROR OCCURS
        .pipe(gulp.dest(paths.css + '*.css'))
        .pipe(livereload());
    });

gulp.task('scripts', function() {
    return gulp.src('angular/app.js')
        .pipe(plumber())
        .pipe(uglify())
        .pipe(gulp.dest('angular/minjs'))
        .pipe(livereload());
    });

gulp.task('watch', function() {
    livereload.listen();
    gulp.watch(paths.sass + '*.scss', ['sass']);
    gulp.watch('angular/app.js', ['scripts']);
    });

gulp.task('default', ['lint', 'sass', 'scripts', 'watch']);

1 个答案:

答案 0 :(得分:0)

感谢@Aperçu发现错误,即require未加('gulp-ruby-sass)。愚蠢的错误。

所以这是我从Gulp-Ruby-Sass 1.0.0-alpha的新文档中得到的答案。新文档指出你必须摆脱gulp src。这是我用来使一切工作的代码。

旧代码

gulp.task('sass', function() {
    return gulp.src(paths.sass + '*.scss')
        .pipe(plumber())
        .pipe(sass({style: 'expanded'})) // HERE IS WHERE THE ERROR OCCURS
        .pipe(gulp.dest(paths.css + '*.css'))
        .pipe(livereload());
    });

新代码

gulp.task('sass', function() {
    return sass(paths.sass, {style: 'expanded'}) 
        .pipe(plumber())
        .pipe(gulp.dest(paths.css))
        .pipe(livereload());
});

注意:新文档不支持globs。