5.0.0 • Published 2 years ago

@bolt/sass-export-data v5.0.0

Weekly downloads
764
License
MIT
Repository
github
Last release
2 years ago

Sass Export Data

Uses custom functions in node-sass to export JSON files from Sass maps and other variables.

Install

npm install --save @theme-tools/sass-export-data

Setup

const config = {
  name: 'export_data', // Name of Sass function
  path: 'path/to/export/folder/' // Folder where to place JSON files
};
const sassExportData = require('@theme-tools/sass-export-data')(config);

Then pass sassExportData to the functions option in node-sass. It'll be the object like it wants, so you could merge it with other functions if needed. This can work with many ways to compile sass: gulp, webpack, basic cli, or anything that utilizes node-sass.

Usage

In your sass declare this mixin to make it easier:

/// Export Sass Data to JSON in `path/to/export/folder/` folder
/// @param {String} $filename - ie `mystuff.json`
/// @param $var - What to turn into JSON
/// @example scss
///   @include export-data-to-lib('filename.json', $sass-map);
@mixin export-data($filename, $var) {
  // The `export_data` function is a custom function added to Sass.
  // The `$data` var is weird, but needed.
  $data: export_data($filename, $var);
};

Then you can do this wherever you'd like:

$x: (
  a: 'Apple',
  b: 'Beer',
);

@include export-data('example.json', $x);

This will create the file example.json in path/to/export/folder/ with:

{
  "a": "Apple",
  "b": "Beer"
}

Details

  • If the file hasn't changed, it won't output. That helps watchers go less crazy.

Special thanks to node-sass-export for inspiration and much of the original code.

5.0.0

2 years ago

4.3.0

2 years ago

4.0.0

3 years ago

3.1.2

3 years ago

3.1.0

3 years ago

3.0.0

3 years ago

2.19.0

4 years ago

2.17.0

4 years ago

2.16.0

4 years ago

2.15.2

4 years ago

2.15.0

4 years ago

2.14.0

4 years ago

2.12.0

4 years ago

2.11.0

4 years ago

2.7.0

5 years ago

2.5.1

5 years ago

2.5.0

5 years ago

2.4.0

5 years ago

2.3.1

5 years ago

2.4.0-beta.0

5 years ago

2.3.0

5 years ago

2.3.0-rc.0

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.2.0-rc.1

5 years ago

2.1.6

6 years ago

2.1.5

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.1.0-beta.0

6 years ago

2.0.0

6 years ago

2.0.0-beta.3

6 years ago

2.0.0-beta.2

6 years ago

2.0.0-beta.1

6 years ago

2.0.0-beta.0

6 years ago