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

jss-lite-loader

v2.0.1

Published

A webpack loader for jss-lite

Downloads

5

Readme

Travis – build status
Coveralls – test coverage
David – status of dependencies
Code style: airbnb

jss-lite-loader

Write stylesheets in JS.
Works with any stack.

 

Installation

npm install [--save] jss-lite-loader

 

Usage

jss-lite-loader is very flexible. Feel free to combine it with other loaders – for example, style-loader for adding the styles to the page or apply-loader for configurable stylesheets.

Easy to use

You can use it like a good old CSS preprocessor like LESS or SASS:

∎ config.js

const color = require('color');

exports.buttonBackground =
  color('#F44336').alpha(0.5).lighten(0.5).rgbaColor();

∎ style.js

const { buttonBackground } = require('./config');

exports.stylesheet = {
  '.button': {
    'width': '50px',
    'background-color': buttonBackground,
  },

  '@media screen and (min-width: 80em)': {
    '.button': {
      'width': '100%',
    },
  },
};

∎ index.js

require('style!jss-lite!./style');

Sharing code between JS and CSS

Here’s a problem I encountered recently, which turned out to be a perfect match for jss-lite-loader. I use a bunch of brand-specific colors in my jss-lite stylesheets:

∎ header.js

const colors = require('material-colors');

const headerColor = exports.headerColor =
  materialColors.grey[800];

exports.stylesheet = {
  '.header': {
    'height': '60px',
    'background-color': headerColor,
  },
};

And here’s the wow. I can use the same values in JS for things CSS can’t do. For example, setting the theme-color:

∎ index.js

const h = require('hyperscript');

// This gets rendered and injected as CSS:
require('style!jss-lite!./header');

// The same file can be imported as a pure JS module, free of side effects:
const { headerColor } = require('./header');

document.head.appendChild(
  h('meta', { name: 'theme-color', content: headerColor })
);

Until now sharing variables between JS and CSS was notoriously difficult.

Flexible thus powerful

Because the API is so simple, you can add lots of features yourself. Here’s an example of unique, auto-generated class names and a configurable stylesheet function (for example, coming from a style framework) in a reusable hyperscript component. Whoah, that’s a lot at once!

∎ style.js

const hash = require('hash-sum')(__filename);

const classes = {
  button = `${hash}-button`,
};

module.exports = ({
  backgroundColor,
}) => ({ stylesheet: {
  [`.${classes.button}`]: {
    'width': '50px',
    'background-color': indigo,
  },

  '@media screen and (min-width: 80em)': {
    [`.${classes.button}`]: {
      'width': '100%',
    },
  },
} });

Object.assign(module.exports, { classes });

∎ button.js

require('style!jss-lite!apply?{ obj: { backgroundColor: "#F44336" } }!./style');
const { classes } = require('./style');

export default () => (
  h(`button.${classes.button}`)
);

 

License

MIT © Tomek Wiszniewski