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

css-local-loader

v1.0.5

Published

a webpack loader to enhance the style-loader to throw when attempting to access non existant selectors and allow combining both local and global css classes.

Downloads

6

Readme

css-local-loader

a webpack loader to enhance the style-loader to throw when attempting to access undefined local classnames and allow combining both local and global css classnames.

It can also be used as an alternative of the classnames module.

IMPORTANT: This module uses ES6 Proxy to be able to throw when the selector required is undefined, in browsers without Proxy support this will just default to the normal behavior. In any case the usage of the helper functions cf and g should still work on all browsers.

motivation

check: https://github.com/css-modules/css-modules/issues/146

TODO: Add tests

install

npm i -D css-local-loader

Usage

module: {
  loaders: [{
    // only files that match .m.scss
    // this is to make the transition easier
    // since now the code will change from
    //
    // import styles from './file.scss'
    // styles.foo // might be undefined
    //
    // to
    //
    // import { locals as styles } from './file.m.scss'
    // styles.foo // will throw if foo is undefined
    //
    test: /\.m\.scss$/,
    loader: 'css-local',
  },
  // important style loader should come after
  {
    test: /\.scss$/,
    exclude: /node_modules/,
    loader: 'style!css?modules&importLoaders=2&sourceMap&localIdentName=[local]___[hash:base64:5]!postcss!sass?outputStyle=expanded&sourceMap',
  }]
}

cf (classFor) an g (globalClassFor)

Two functions are also exported when a file containing local css is imported:

cf (classFor)

cf is abbreviation for classFor. This method will return the local identifier for the provided className.

Example:

Given test.m.scss

.test {
  display: block;
}

.demo {
  display: inline-block;
}

.foo {
  width: 100%;
}

then using cf:

import { locals, cf } from './test.m.scss';

// NOTE: __xxxx is just a placeholder for whatever renaming strategy is selected

locals.test; // will return something like test__xxxx
locals.foo; // will return something like foo__xxxx
locals.demo // will return something like demo__xxxx
locals.iDontExist // will throw becasue it does not exists

cf('test demo'); // will return something like 'test__xxxx demo__xxx'
cf('test notfound') // will throw because of not found
cf({ test: true, notFound: false }); // will not throw since notFound is not accessed
cf({ test: true, demo: true }); // will return something like 'test__xxxx demo__xxx'
cf({ test: true, notFound: true }); // will throw because notFound is not defined in the file

g or (globalClassFor)

g is the abbreviation for globalClassFor this is handy when a global class need to be mixed with the local classes. This function return an object, so it is actually intended to be used in combination with cf like described below

import { cf, g } from './test.m.css';
cf('test demo', g('global classes')) // will return something like 'test__xxxx demo__xxxx global classes'
cf('test demo', g({ globalClass: true, button: false })); // will return 'test__xxxx demo__xxxx globalClass'

Changelog

changelog

License

MIT