Gulp-ruby-sass错误:

时间:2015-12-30 22:38:59

标签: javascript sass gulp gulp-ruby-sass

gulp插件 gulp-ruby-sass 在编译sass文件时不起作用。


    'use strict';

    var path = require('path');
    var gulp = require('gulp');
    var conf = require('./conf');

    var browserSync = require('browser-sync');

    var $ = require('gulp-load-plugins')();

    var wiredep = require('wiredep').stream;
    var _ = require('lodash');

    gulp.task('styles-reload', ['styles'], function() {
      return buildStyles()
        .pipe(browserSync.stream());
    });

    gulp.task('styles', function() {
      return buildStyles();
    });

    var buildStyles = function() {
      var sassOptions = {
        style: 'expanded'
      };

      var injectFiles = gulp.src([
        path.join(conf.paths.src, '/app/**/*.scss'),
        path.join('!' + conf.paths.src, '/app/index.scss')
      ], { read: false });

      var injectOptions = {
        transform: function(filePath) {
          filePath = filePath.replace(conf.paths.src + '/app/', '');
          return '@import "' + filePath + '";';
        },
        starttag: '// injector',
        endtag: '// endinjector',
        addRootSlash: false
      };

      var cssFilter = $.filter('**/*.css', { restore: true });

      return gulp.src([
        path.join(conf.paths.src, '/app/index.scss')
      ])
        .pipe($.inject(injectFiles, injectOptions))
        .pipe(wiredep(_.extend({}, conf.wiredep)))
        .pipe($.rubySass(sassOptions)).on('error', conf.errorHandler('RubySass'))
        .pipe(cssFilter)
        .pipe($.sourcemaps.init({ loadMaps: true }))
        .pipe($.autoprefixer()).on('error', conf.errorHandler('Autoprefixer'))
        .pipe($.sourcemaps.write())
        .pipe(cssFilter.restore)
        .pipe(gulp.dest(path.join(conf.paths.tmp, '/serve/app/')));
    };


TypeError: glob pattern string required
    at new Minimatch (/home/john/sac_srvs/new_srvs/sachin/node_modules/gulp-ruby-sass/node_modules/glob/node_modules/minimatch/minimatch.js:108:11)
    at setopts (/home/john/sac_srvs/new_srvs/sachin/node_modules/gulp-ruby-sass/node_modules/glob/common.js:112:20)
    at new GlobSync (/home/john/sac_srvs/new_srvs/sachin/node_modules/gulp-ruby-sass/node_modules/glob/sync.js:38:3)
    at Function.globSync [as sync] (/home/john/sac_srvs/new_srvs/sachin/node_modules/gulp-ruby-sass/node_modules/glob/sync.js:24:10)
    at /home/john/sac_srvs/new_srvs/sachin/node_modules/gulp-ruby-sass/index.js:68:21
    at Array.forEach (native)
    at Object.gulpRubySass (/home/john/sac_srvs/new_srvs/sachin/node_modules/gulp-ruby-sass/index.js:67:10)
    at buildStyles (/home/john/sac_srvs/new_srvs/sachin/gulp/styles.js:50:13)
    at Gulp.sassOptions.style (/home/john/sac_srvs/new_srvs/sachin/gulp/styles.js:20:10)
    at module.exports (/home/john/sac_srvs/new_srvs/sachin/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/home/john/sac_srvs/new_srvs/sachin/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/home/john/sac_srvs/new_srvs/sachin/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/home/john/sac_srvs/new_srvs/sachin/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:415:13)
    at Function.Module.runMain (module.js:499:11)

1 个答案:

答案 0 :(得分:2)

这是一个棘手的问题。您似乎正在使用generator-gulp-angular并选择ruby-sass。不幸的是,gulp-ruby-sass的API在9月份已经发生了变化(发布了2.0.0版本),并且自那时起生成器没有更新。简而言之:新API需要传递给流工厂方法的源文件 .pipe($.rubySass([**SOURCE FILES HERE**], sassOptions)).on('error', conf.errorHandler('RubySass')) 将构建链与injectwiredep等其他插件组合时,这基本上是不可能的。 我的建议是使用node-sass代替 - 如果您当然不需要ruby-sass