Skip to content

EnoahNetzach/extract-scss-variables

Repository files navigation

Extract SCSS variables

Build Status Build status Coverage Status NPM Version

An utility for extracting variables from .scss files.

Installation

npm install --save-dev extract-scss-variables

Node SASS must be installed, too.
If not present already, just install it with:

npm install --save-dev node-sass

Usage

var extractScssVariables = require('extract-scss-variables');
var variables = extractScssVariables({
  entryPoint: entryPath,
  files: filePaths,
  sassOptions: { 
    includePaths: includePaths,
  },
});

Internally variable declarations are extracted and their value is appended at the end of a copy of the provided entryPath file.
Using the "content:" trick:

#test {
  content: "#{$extracted-value}";
}

and compiling the entryPath copy with node-sass, the computed values could be easily extracted.

CLI

Running the CLI version will produce a JSON file containing all extracted variables.

  • <entry-point>: SCSS entry point
  • -f, --file <path>: path to a .scss file from where to extract the variables. It can occur multiple times
  • -c, --sass-config: JSON string or path to a JSON file with node-sass additional config
  • -o, --output <path>: path where to save the JSON output

For example:

extract-scss-values bundle.scss -f _globals.scss -f _settings.scss

Releases

No releases published

Packages

No packages published