sassgulpgulp-sassgulp-ruby-sass

gulp-json-sass - Cannot include json file


Source link - I don't know what is missing here

Everything fine if I am not including json file

1) gulpfile.js

var jsonSass = require('gulp-json-sass'),
    gulp = require('gulp'),
    concat = require('gulp-concat'),
    sass = require('gulp-ruby-sass');


    gulp.task('sass', function() {
      return gulp
        .src(['sass/example.json', 'sass/example.scss'])
        .pipe(jsonSass({
          sass: true
        }))
        .pipe(concat('output.scss'))
        .pipe(sass())
        .pipe(gulp.dest('out/'));
});

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

2) example.json

{
    "color": "blue"
}

3) example.scss file

.test{
    color:$color; 
}

4) error message enter image description here


Solution

  • 1. You want to output SCSS, not SASS. That means your sass option for gulp-json-sass is wrong. From the docs:

    If truthy, output valid sass variables. If false, output scss variables.

    2. You can't use gulp-ruby-sass in a pipe. From the docs:

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

    That means .pipe(sass()) won't work. You have to use gulp-sass instead of gulp-ruby-sass.

    var jsonSass = require('gulp-json-sass'),
        gulp = require('gulp'),
        concat = require('gulp-concat'),
        sass = require('gulp-sass');
    
    gulp.task('sass', function() {
      return gulp.src(['sass/example.json', 'sass/example.scss'])
        .pipe(jsonSass({
          sass: false 
        }))
        .pipe(concat('output.scss'))
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest('out/'));
    });