Gulp Sass编译错误

时间:2017-09-18 00:11:47

标签: compiler-errors sass compilation gulp

这是我当前的目录树: Directory Tree

这是我的gulpfile.js代码:

var gulp = require ('gulp'),
    gutil = require('gulp-util'),
    uglify = require('gulp-uglify'),
    sass = require('gulp-ruby-sass'),
    concat = require('gulp-concat'),
    livereload = require('gulp-livereload'),
    lr = require('tiny-lr'),
    server = lr();

var jsSources = ['components/scripts/scriptOne.js',
                 'components/scripts/scriptTwo.js'
];

var sassSources = [
  'comptonents/sass/*.scss'
];

gulp.task('js', function() {
    gulp.src(jsSources)
              .pipe(uglify())
              .pipe(concat ('script.js'))
              .pipe(gulp.dest('js'));
});

gulp.task('sass', function() {
  gulp.src(sassSources)
    .pipe(sass({style: 'expanded', lineNumbers: true}))
    .on('error', gutil.log)
    .pipe(concat('style.css'))
    .pipe(gulp.dest('css'))
    .pipe(livereload());
});


gulp.task('watch', function() {
  var server = livereload();
  gulp.watch(jsSources, ['js']);
  gulp.watch(sassSources, ['sass']);
  gulp.watch(['js/script.js', '*.html'], function(e) {
    server.changed(e.path);
  });
});



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

每当我尝试运行gulp来编译我的sass时,我得到的错误是输出以下命令。

       19:55:01] Using gulpfile ~/Desktop/coffeescript/gulpfile.js
[19:55:01] Starting 'sass'...
[19:55:01] 'sass' errored after 21 ms
[19:55:01] TypeError: glob pattern string required
    at new Minimatch (/Users/Aquinas/Desktop/coffeescript/node_modules/gulp-ruby-sass/node_modules/minimatch/minimatch.js:116:11)
    at setopts (/Users/Aquinas/Desktop/coffeescript/node_modules/gulp-ruby-sass/node_modules/glob/common.js:118:20)
    at new GlobSync (/Users/Aquinas/Desktop/coffeescript/node_modules/gulp-ruby-sass/node_modules/glob/sync.js:40:3)
    at Function.globSync [as sync] (/Users/Aquinas/Desktop/coffeescript/node_modules/gulp-ruby-sass/node_modules/glob/sync.js:26:10)
    at /Users/Aquinas/Desktop/coffeescript/node_modules/gulp-ruby-sass/index.js:68:21
    at Array.forEach (native)
    at gulpRubySass (/Users/Aquinas/Desktop/coffeescript/node_modules/gulp-ruby-sass/index.js:67:10)
    at Gulp.<anonymous> (/Users/Aquinas/Desktop/coffeescript/gulpfile.js:27:11)
    at module.exports (/Users/Aquinas/Desktop/coffeescript/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/Users/Aquinas/Desktop/coffeescript/node_modules/orchestrator/index.js:273:3)

请帮我解决这个问题。谢谢。

编辑一:更改了var SassSources中的拼写错误。但是,仍然输出错误。我甚至没有日志来检查它。糟透了,我确定我已经启用了log命令。无论如何,如果它有帮助,那就是gulp plugins树:

Gulp plugins tree

编辑二:已解决!!我不得不指出实时重载号码(从我的index.html中的xxx提供)。我不得不对我的代码和中提琴进行一些调整!它像面包和黄油一样运行。

调整后的代码:

gulp.task('watch', function() {
  livereload.listen(35732);
  var server = livereload();
  gulp.watch(jsSources, ['js']);
  gulp.watch(coffeeSources, ['coffee']);
  gulp.watch(sassSources, ['sass']);
  gulp.watch(['js/script.js', '*.html'], function(e) {
    livereload.changed(e.path);
  });
});

问题是因为我使用的代码有点过时,因为livereload的监视工作不正常。

1 个答案:

答案 0 :(得分:0)

这可能是因为 gulp.src()需要字符串而不是数组作为条目文件。只需将其从数组更改为字符串,您就可以开始使用了。