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

prepend-selector-postcss

v0.4.7

Published

PostCSS plugin Prepend selector for each rule. Optional exclude rules to prevent prepending 2021

Downloads

1,673

Readme

PostCSS Prepend Selector

[PostCSS] plugin Prepend selector for each rule with optional exclude existing selector from prepending.

[PostCSS]: Version 8 https://github.com/postcss/postcss

The intention

The intention I had extended the plugin to create a user interface for the web using Vue-js and styled it with Tailwind-css. The Vue-js panel was integrated into an existing website/application. So the styles created with Tailwind-css should be used exclusively in the Vue-js application.

That means this plugin is not really well developed. However, it serves its purpose without claiming to be a really well-tested script.

Usage in postcss.config.js with prepend-selector-postcss

// postcss.config.js
const autoprefixer = require('autoprefixer');
const tailwindcss = require('tailwindcss');
// https://github.com/ledniy/postcss-prepend-selector
const prepend = require('prepend-selector-postcss')({
    // requiured
    selector: '.myPrefix ',
    // optional can be omitted
    exclude: ['.living_classname_to_prevent_from_prefixing '],
    // optional can be omitted
    excludePart: ['.grid-'],
    // optional can be omitted -> body{some unwanted global reset stuff}  -> body .selector{some unwanted global reset stuff}
    appendTo:['body'],
    // optional can be omitted -> Prefixing special selectors with a string that not exists in html tags to prevent using "body" - selector
    // body{some unwanted global reset stuff}  -> i_had_made_invalid_body{some unwanted global reset stuff}
    makeInvalid: {
        selectors:     ['body'],
        invalidPrefix: 'i_had_made_invalid_'
    }
})
module.exports = {
    purge  : [
        './public/**/*.html',
        './src/**/*.{js,jsx,ts,tsx,vue}',
    ],
    plugins: [
        tailwindcss,
        prepend,
        autoprefixer,
    ],
};

Prefix all

// minimal example
postcss([require('prepend-selector-postcss')({
    selector: '.myPrefix '
})])

Original Css

.foo {
    /* Input example */
}

.foo, .bar {
    /* Input example */
}

Result

.myPrefix .foo {
    /* Output example */
}

.myPrefix .foo, .myPrefix .bar {
    /* Output example */
}

Prefix all but exclude something

// example with exclude
postcss([require('prepend-selector-postcss')({
    selector: '.myPrefix ',
    exclude : ['#living_id_prefix_to_prevent_from_prefixing ', '.living_classname_to_prevent_from_prefixing '],
})])

Original Css

.foo {
    /* Input example */
}

.foo, .bar {
    /* Input example */
}

#living_id_prefix_to_prevent_from_prefixing {
    /* Input example */
}

.living_classname_to_prevent_from_prefixing {
    /* Input example */
}

.living_classname_to_prevent_from_prefixing .somethingSub {
    /* Input example */
}

Result

.myPrefix .foo {
    /* Output example */
}

.myPrefix .foo, .myPrefix .bar {
    /* Output example */
}

/* not prefixed */
#living_id_prefix_to_prevent_from_prefixing {
    /* Input example */
}

/* not prefixed */
.living_classname_to_prevent_from_prefixing {
    /* Input example */
}

/* not prefixed */
.living_classname_to_prevent_from_prefixing .somethingSub {
    /* Input example */
}

Prefix all but exclude Start-With


// exclude everything which starts with ".grid"
// excludes .grid-x | .grid .mySubClass
postcss([require('prepend-selector-postcss')({
    selector   : '.myPrefix ',
    excludePart: ['.grid']
})])

Original Css

.foo {
    /* Input example */
}

.foo, .bar {
    /* Input example */
}

.grid .padding {
    /* Input example */
}

.grid-x .cell {
    /* Input example */
}

Result

.myPrefix .foo {
    /* Output example */
}

.myPrefix .foo, .myPrefix .bar {
    /* Output example */
}

/* not prefixed */
.grid .padding {
    /* Input example */
}

/* not prefixed */
.grid-x .cell {
    /* Input example */
}

All together

// Full example
postcss([require('prepend-selector-postcss')({
    selector   : '.myPrefix ',
    exclude    : ['#living_id_prefix_to_prevent_from_prefixing ', '.living_classname_to_prevent_from_prefixing '],
    excludePart: ['.grid']
})])

Original Css

.foo {
    /* Input example */
}

.foo, .bar {
    /* Input example */
}

#living_id_prefix_to_prevent_from_prefixing {
    /* Input example */
}

.living_classname_to_prevent_from_prefixing {
    /* Input example */
}

.living_classname_to_prevent_from_prefixing .somethingSub {
    /* Input example */
}

.grid .padding {
    /* Input example */
}

.grid-x .cell {
    /* Input example */
}

Result

.myPrefix .foo {
    /* Output example */
}

.myPrefix .foo, .myPrefix .bar {
    /* Output example */
}

/* not prefixed */
#living_id_prefix_to_prevent_from_prefixing {
    /* Input example */
}

/* not prefixed */
.living_classname_to_prevent_from_prefixing {
    /* Input example */
}

/* not prefixed */
.living_classname_to_prevent_from_prefixing .somethingSub {
    /* Input example */
}

/* not prefixed */
.grid .padding {
    /* Input example */
}

/* not prefixed */
.grid-x .cell {
    /* Input example */
}

Note

Please do not forget "selector" and "exclude" the space at the end of the string. exclude and excludePart are not tested. feel free to fork.

See [PostCSS] docs for examples for your environment.

Forked from

https://github.com/ledniy/postcss-prepend-selector