这是我当前的目录树: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命令。无论如何,如果它有帮助,这里是吞咽插件树:
编辑二:已解决!!我必须指出实时重新加载的数字(从我的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的手表不工作,因为我使用的代码有点过时。
发布于 2017-09-18 14:21:21
这可能是因为gulp.src()需要一个字符串而不是数组作为入口文件。只需将其从数组更改为字符串,就可以了。
https://stackoverflow.com/questions/46269999
复制相似问题