Gulp Sass not compiling partials

后端 未结 6 1938
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-18 02:49

So I am using Gulp Sass with gulp-changed (i\'ve also tried gulp-newer with the updated syntax changes) and watching all the scs

6条回答
  •  情书的邮戳
    2021-01-18 03:09

    I use https://github.com/vigetlabs/gulp-starter as a template with https://github.com/berstend/gulp-sass-inheritance

    It works but only with 2 levels of deep

    var gulp            = require('gulp');
    var debug           = require('gulp-debug');
    var browserSync     = require('browser-sync');
    var sass            = require('gulp-sass');
    var sourcemaps      = require('gulp-sourcemaps');
    var handleErrors    = require('../lib/handleErrors');
    var autoprefixer    = require('gulp-autoprefixer');
    var path            = require('path');
    var cached          = require('gulp-cached');
    var sassInheritance = require('gulp-sass-inheritance');
    var gulpif          = require('gulp-if');
    var filter          = require('gulp-filter');
    var duration        = require('gulp-duration');
    var notify          = require('gulp-notify');
    
    var paths = {
        src : 'app/styles',
        dest: 'grails-app/assets'
    }
    
    
    var isPartial = function (file) {
        return /_/.test(file.relative);
    }
    
    //set global.isWatching = true on gulp watch
    
    gulp.task('css', function () {
        return gulp.src(paths.src)
            //.pipe(debug({title: 'before cache:'}))
            .pipe(gulpif(global.isWatching, cached('sass')))
            //.pipe(gulpif(global.isWatching, debug({title: 'after cache:'})))
            .pipe(gulpif(isPartial, sassInheritance({dir: path.join(config.root.src, config.tasks.css.src), debug: false}).on('error', handleErrors))) //,
            .pipe(debug({title: 'after sassInheritance:'}))         
            //.pipe(debug({title: 'after filter:'}))
            .pipe(sourcemaps.init())
            .pipe(sass()).on('error', handleErrors)
            .pipe(debug({title: 'after sass:'}))
            //.pipe(notify('Sass compiled <%= file.relative %>'))
            .pipe(autoprefixer(config.tasks.css.autoprefixer))
            .pipe(sourcemaps.write())
            .pipe(gulp.dest(paths.dest))
            //.pipe(duration('after sass'))
            .pipe(debug({title: 'before browserSync:'}))
            .pipe(browserSync.reload({stream: true}))
    })
    

提交回复
热议问题