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

postcss-prefixwrap

v1.53.0

Published

A PostCSS plugin that is used to wrap css styles with a css selector to constrain their affect on parent elements in a page.

Downloads

246,789

Readme

PostCSS Prefix Wrap

CI GitHub Pipeline SAST GitHub Pipeline Latest Release NPM Downloads Per Week

A PostCSS (postcss.org) plugin which prepends a selector to CSS styles to constrain their effect on parent elements in a page.

| Supports | Versions | | :------------------------------------------- | :-------------------------------- | | Bun (bun.sh) | latest | | Deno (deno.com) | v2 | | NodeJS (nodejs.org) | v18, v19, v20, v21, v22 | | PostCSS (postcss.org) | v7, v8 |

⚠️ PostCSS v7 support is no longer validated in automated test cases, and will be removed entirely in a future release.

How to use this plugin?

⚠️ These instructions are only for this plugin. See the PostCSS (postcss.org) website for framework information.

Install

| Package Manager or Runtime | Command | | :---------------------------------------------------------------------- | :------------------------------------------------------- | | Bun (bun.sh) | bun add postcss-prefixwrap --dev --exact | | Deno (deno.com) | deno add npm:postcss-prefixwrap --dev | | NPM (npmjs.com) | npm install postcss-prefixwrap --save-dev --save-exact | | PNPM (pnpm.io) | pnpm add postcss-prefixwrap --save-dev --save-exact | | Yarn (yarnpkg.com) | yarn add postcss-prefixwrap --dev --exact |

Configure

Add to your PostCSS (postcss.org) configuration.

const PostCSS = require("gulp-postcss");
const PrefixWrap = require("postcss-prefixwrap");

PostCSS([PrefixWrap(".my-custom-wrap")]);

Container

Add the container to your markup.

<div class="my-custom-wrap"><!-- Your existing markup. --></div>

View

View your CSS, now prefix-wrapped.

Before

p {
    color: red;
}

body {
    font-size: 16px;
}

After

.my-custom-wrap p {
    color: red;
}

.my-custom-wrap {
    font-size: 16px;
}

What options does it have?

PrefixWrap(".my-custom-wrap", {
    // You may want to exclude some selectors from being prefixed, this is
    // enabled using the `ignoredSelectors` option.
    ignoredSelectors: [":root", "#my-id", /^\.some-(.+)$/],

    // You may want root tags, like `body` and `html` to be converted to
    // classes, then prefixed, this is enabled using the `prefixRootTags`
    // option.
    // With this option, a selector like `html` will be converted to
    // `.my-container .html`, rather than the default `.my-container`.
    prefixRootTags: true,

    // In certain scenarios, you may only want `PrefixWrap()` to wrap certain
    // CSS files. This is done using the `whitelist` option.
    // ⚠️ **Please note** that each item in the `whitelist` is parsed as a
    // regular expression. This will impact how file paths are matched when you
    // need to support both Windows and Unix like operating systems which use
    // different path separators.
    whitelist: ["editor.css"],

    // In certain scenarios, you may want `PrefixWrap()` to exclude certain CSS
    // files. This is done using the `blacklist` option.
    // ⚠️ **Please note** that each item in the `blacklist` is parsed as a
    // regular expression. This will impact how file paths are matched when you
    // need to support both Windows and Unix like operating systems which use
    // different path separators.
    // If `whitelist` option is also included, `blacklist` will be ignored.
    blacklist: ["colours.css"],

    // When writing nested css rules, and using a plugin like `postcss-nested`
    // to compile them, you will want to ensure that the nested selectors are
    // not prefixed. This is done by defining the `nested` property and setting
    // the value to the selector prefix being used to represent nesting, this is
    // most likely going to be `"&"`.
    nested: "&",
});

What problems can it solve?

PostCSS Prefix Wrap can be used to solve multiple different problems. The following articles give some concrete examples:

How to contribute?

Read our Contributing Guide to learn more about how to contribute to this project.

Is this project secure?

Read our Security Guide to learn how security is considered during the development and operation of this plugin.

License

The MIT License is used by this project.