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

pcss-loader

v1.0.3

Published

Webpack loader for pcss files

Downloads

52

Readme

pcss-loader

A loader for Webpack that imports pcss files and return js modules.

How to setup in your webpack configuration

Install with npm i -D pcss-loader. Then your webpack configuration must contain the following module:

...
module: {
    rules: [
    ...
        {
            // You can use antoher extension
            test: /\.pcss$/i,
            // You can also exclude, but inclusion is
            // more specific and more predictable
            include: 'your_src_folder_path',
            use: {
                loader: 'pcss-loader',
                // Not mandatory
                options: {}
            }
        }
    ]
},
...

Default options

options: {
    // Set to true to minify the output, important for production
    minified: false,
    // Default values for the env
    presetEnv: {
        stage: 0,
        features: ['css-nesting'],
        browsers: 'cover 100%'
    },
    // Array of additionnal plugins
    // you can add any post-css plugin
    customPlugins: []
}

You can read the documentation about postcss-preset-env to learn more about the options you can pass to presetEnv.

Plugins in use

You can add any plugins you want to post-css with the customPlugins array. But here are the ones currently in use.

Input and output

If you have the two following pcss files:

/* Colors.pcss */
$mainColor: #00c;

/* Styles.pcss */
@import 'src_path/Colors.pcss';

body {
  color: #000;
}

.__SCOPE {
  color: #c00;

  > .example {
    color: $mainColor;
  }
}

And you import them in a JavaScript file with import AppStyles from './AppStyles.pcss';, you obtain this object:

{
    hash: "_d9ce6323d17badc0ff20482741b70d84",
    styles: `
        body {
            color: #000;
        }

        ._d9ce6323d17badc0ff20482741b70d84 {
            color: #c00;
        }

        ._d9ce6323d17badc0ff20482741b70d84 > .example {
            color: #00c;
        }
    `,
}

It should be injected in a style tag in your DOM.

The value of styles will be minified if you pass minified: true in the options and will be: body{color:#000}._8fd83ea9dc8f28944de69aac4284bba3{color:#c00}._8fd83ea9dc8f28944de69aac4284bba3>.example{color:#00c}

The .__SCOPE class

The loader uses that class to scope your styles. Then you can use the hash returned by the loader as a class for the container and so the styles will be scoped only to his children.

You can also store the hash to make sure that you don't inject twice the same styles.

The styles in body are not nested in the __SCOPE class. The loader put them in the global scope.