npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-sass-external-variables

v0.0.3

Published

Parses and external JSON source, injecting properties subsequently available as part to your SASS/SCSS files

Downloads

1

Readme

gulp-sass-external-variables Build Status GitHub issues Version

Parses and external JSON source, injecting properties which are subsequently available as part of SASS processing

Note: This is heavily based on the seemingly inactive gulp-json-sass so much of the credit must go to it's author.

My beef with the current solution, is it's not the greatest at handling complex object structures, and I wanted a way to parse JSON.array values to SASS Lists.

It also tripped up if you tried to pass it anything other than numerical values.

Coming Soon:

  • Parsing Object structures to Maps ( for SASS 3.3 and beyond )
  • Additional configuration settings to define if arrays are flattened to lists or not, to be passed in options object

This process is useful for setting up global variables and flags that effect what your final .css file will contain - for example if you wanted to produce multiple themed based instances of a core CSS file based on build-time iterations.

Installing

The usual npm jive to install module and all it's dependencies...

npm i --save gulp-sass-external-variables

Using

Once installed the package is interfaced directly into your gulp task as part of your normal SASS compilation.

The module requires a .json file to complete; the contents of which are injected in to the files and subsequently available

Personally I'm a fan of gulp-load-plugins to do the heavy lifting of creating your package varialbes, but for verbosities sake, the below examples define these manually

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(['./external.json', '/path/to/your/base/sass/file.scss'])
    .pipe(sassExternalVariables({
      sass: false
    }))
    .pipe(concat('output.sass'))
    .pipe(sass())
    .pipe(gulp.dest('dest/'));
});

This will build a new .css file named output to the dest folder. So assuming you also had the following:

In the root of your project a file external.json

{
  "best-olympics": "London",
  "array-to-list": [ "gold", "silver", "bronze" ],
  "second": {
    "best": "Rio"
  }
}

... and where ever you store you main SASS library, a file file.scss

@each $item in $array-to-list {
  .medal--#{$item} {
    content: '#{$item}';
  }
}

div.heading { content: $best-olympics; }
div.subheading { content: $second-best; }

Note the injected code is inserted at the very top of this document.

This will result in the below CSS being generated

.medal--gold { content: 'gold'; }
.medal--silver { content: 'silver'; }
.medal--bronze { content: 'bronze'; }
div.heading { content: 'London'; }
div.subheading { content: 'Rio'; }