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

ignore-styles

v5.0.1

Published

Ignore imported style files when running in Node

Downloads

528,201

Readme

ignore-styles

Version Build Status License Downloads Standard

A babel/register style hook to ignore style imports when running in Node. This is for projects that use something like Webpack to enable CSS imports in JavaScript. When you try to run the project in Node (to test in Mocha, for example) you'll see errors like this:

SyntaxError: /Users/brandon/code/my-project/src/components/my-component/style.sass: Unexpected token (1:0)
> 1 | .title
| ^
2 |   font-family: serif
3 |   font-size: 10em
4 |

To resolve this, require ignore-styles with your mocha tests:

mocha --require ignore-styles

See DEFAULT_EXTENSIONS for the full list of extensions ignored, and send a pull request if you need more.

Note: This is not for use inside Webpack. If you want to ignore extensions in Webpack you'll want to use a loader like ignore-loader. This is for use in Node outside of your normal Webpack build.

Installation

$ npm install --save-dev ignore-styles

More Examples

To use this with multiple Mocha requires:

mocha --require babel-register --require ignore-styles

You can also use it just like babel/register:

import 'ignore-styles'

In ES5:

require('ignore-styles')

To customize the extensions used:

import register from 'ignore-styles'
register(['.sass', '.scss'])

To customize the extensions in ES5:

require('ignore-styles').default(['.sass', '.scss']);

Custom handler

By default, a no-op handler is used that doesn't actually do anything. If you'd like to substitute your own custom handler to do fancy things, pass it as a second argument:

import register from 'ignore-styles'
register(undefined, () => ({styleName: 'fake_class_name'}))

The first argument to register is the list of extensions to handle. Leaving it undefined, as above, uses the default list. The handler function receives two arguments, module and filename, directly from Node.

Why is this useful? One example is when using something like react-css-modules. You need the style imports to actually return something so that you can test the components, or the wrapper component will throw an error. Use this to provide test class names.

Another use case would be to simply return the filename of an image so that it can be verified in unit tests:

const _ = require('lodash');
const path = require('path');

register(undefined, (module, filename) => {
  if (_.some(['.png', '.jpg'], ext => filename.endsWith(ext))) {
    module.exports = path.basename(filename);
  }
})

If the filename ends in '.png' or '.jpg', then the basename of the file is returned as the value of the module on import.

License

The MIT License (MIT)

Copyright (c) 2015 Brainspace Corporation