How to take values from a JSON and pass as SASS variables with Grunt

Asked

Viewed 69 times

0

I need to compile templates using Grunt and I want to put the color settings inside a JSON file that will be inside each layout folder, that is, I need to use Grunt to read JSON and pass the values as variables to compile SASS.

  • Why not use these variables directly in SASS files?

1 answer

0

There is this plugin for Grunt https://www.npmjs.com/package/grunt-json-to-sass

Installation

npm install grunt-json-to-sass --save-dev

Setup

grunt.initConfig({
  json_to_sass: {
    your_target: {
      files: [
        {
          src: [
            'example.json'
          ],
          dest: '_example.scss'
        }
      ]
    },
  },
});

I hope it helps!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.