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-inject-scss

v0.0.8

Published

Transpile Javascript variables into SCSS variables during the pipe task.

Downloads

12

Readme

Gulp Inject SCSS

Inject Javascript arrays to render SCSS variables or imports during a pipe task.

Basically the same principle as Postilabs Inject SCSS page, only this variation works within streams/pipes. So you can inject variables or imports directly before your SCSS compilation.

So you could use this to respect environment paths that differ between development and production servers for example. Or keep unit sizes consistent between Javascript and CSS. Or maybe you just need to define a special custom property bespoke to your needs.

Installation

npm i gulp-inject-scss --save

Setup

const injectScss = require('gulp-inject-scss')

Injecting Variables

Pass an associative array where the keys are the css properties and the values are the css values.

gulp.task('sass', () => {

  let variables = {
   'images':'"../assets/images/"',
   'max-height':'100vh',
   'browser-version':11
  }

  return gulp.src(config.sources.sass)
  .pipe(injectScss(variables))
  .pipe(gulpsass({outputStyle: 'compressed'}))
  .pipe(gulp.dest("cssfile.css"))
});

SCSS input

:root { --browser-version : #{$browser-version}; }
body {
  background-image:url(#{$images} + 'wallpaper.jpg');
  max-height:#{$max-height};
}

CSS output

:root { --browser-version : 11; }
body {
  background-image:url(../assets/images/wallpaper.jpg);
  max-height:100vh;
}

Sass Maps

You can also pass in nested objects, which will resolve to a Sass Map.


let variables = {
  'images':'"../assets/images/"',
  'max-height':'100vh',
  'browser-version':11,
  'themes' : {
    'primary' : '#FFF8DC',
    'secondary' : '#EFF0F1'
  }
}

SCSS

The following won't actually be rendered anywhere for you to see. It's done entirely dynamically. This is just an idea of what becomes available to you within your scss development.

$themes : (
  primary : '#FFF8DC',
  secondary : '#EFF0F1'
);

Injecting Imports

Pass an array of strings and render each one as an css @import.

gulp.task('sass', () => {

  let imports = {
   'vendor/marknotton/doggistyle/dist/_doggistyle.scss',
   'settings/_symbols.scss'
  }

  return gulp.src(config.sources.sass)
  .pipe(injectScss(imports))
  .pipe(gulpsass({outputStyle: 'compressed'}))
  .pipe(gulp.dest("cssfile.css"))
});

SCSS

The following won't actually be rendered anywhere for you to see. It's done entirely dynamically. This is just an idea of what becomes available to you within your scss development.

@import 'vendor/marknotton/doggistyle/dist/_doggistyle';
@import 'settings/_symbols.scss';

Injecting both Variables and Imports

To use both injection methods, you can simply include both array types in any order.

.pipe(injectScss(imports, variables))