简体   繁体   中英

gulp-ruby-sass Error: must provide pattern

This is my directory structure:

这里

I set up my workstation, and I set up my Gulp File to work on my folder format, but it is not working properly.

This is my Gulp File:

var gulp      = require('gulp'),
    sass        = require('gulp-ruby-sass'),
    imagemin    = require('gulp-imagemin'),
    changed     = require('gulp-changed'),
    browserSync = require('browser-sync'),
    livereload = require('gulp-livereload'),    
    gp_concat = require('gulp-concat'),
    gp_rename = require('gulp-rename'),
    gp_uglify = require('gulp-uglify'),
    watch = require('gulp-watch');


gulp.task('sass', function () {
  gulp.src('./app/template/css/style_v1.scss')
    .pipe(sass())
    .on('error', function (err) { console.log(err.message); })
    .pipe(gulp.dest('./dist/css'))
    .pipe(livereload());
});

gulp.task('compress', function() {
  gulp.src('./app/*.js')
   .pipe(gp_concat('concat.js'))
        .pipe(gulp.dest('dist'))
        .pipe(gp_rename('script.min.js'))
        .pipe(gp_uglify())
        .pipe(gulp.dest('./dist/js'));
});

gulp.task('jpg', function() {
    gulp.src('./template/img/**/*.*')
        .pipe(changed('./dist/img/'))
        .pipe(imagemin({
            progressive: true
        }))
        .pipe(gulp.dest('./dist/img/'));
});

gulp.task('browser-sync', function() {
    browserSync.init(['./dist/css/**', 'index.php'], {
        server: {
            baseDir: './',
            index: 'index.php'
        }
    });
});

gulp.task('watch', ['sass', 'browser-sync','compress'], function () { 
    return watch('./app/template/css/style_v1.scss', function () {
        gulp.src('./app/template/css/style_v1.scss')
            .pipe(gulp.dest('build'));
    });
});

When I run gulp watch it returns this:

(node:6668) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
[08:42:23] Using gulpfile /var/www/html/evandro/sistema_metas/gulpfile.js
[08:42:23] Starting 'sass'...
[08:42:23] 'sass' errored after 7.09 ms
[08:42:23] Error: must provide pattern

What is the problem?

I have another code, the CSS Watch does not work, just watch HTML, What can it be?

gulp-ruby-sass works differently from other gulp plugins. You don't pass it to .pipe() . If you take a look at the documentation it says the following:

Use gulp-ruby-sass instead of gulp.src to compile Sass files.

That means you have to use it like this:

var sass = require('gulp-ruby-sass');

gulp.task('sass', function () {
  return sass('./app/template/css/style_v1.scss')
    .on('error', function (err) { console.log(err.message); })
    .pipe(gulp.dest('./dist/css'))
    .pipe(livereload());
});

Alternatively you can use the gulp-sass plugin instead of gulp-ruby-sass . It doesn't use the Ruby implementation of SASS, but rather the C implementation (libsass). It allows you to use .pipe() as you normally would for most other gulp plugins:

var sass = require('gulp-sass');

gulp.task('sass', function () {
  return gulp.src('./app/template/css/style_v1.scss')
    .pipe(sass())
    .on('error', function (err) { console.log(err.message); })
    .pipe(gulp.dest('./dist/css'))
    .pipe(livereload());
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM