Giter Site home page Giter Site logo

postcss-scope's Introduction

postcss-scope ๐Ÿ”ญ

A small plugin to allow you to scope your css with a custom selector

Installation

# pnpm
pnpm add postcss-scope --save-dev

# npm
npm install postcss-scope --save-dev

# yarn
yarn add postcss-scope --dev

Setup

Basic

// postcss.config.js

export default {
    plugins: {
        "postcss-scope": ".foo",
    },
};

Multiple scopes

// postcss.config.js

export default {
    plugins: {
        "postcss-scope": [".foo", ".bar"],
    },
};

With Tailwind

// postcss.config.js

export default {
    plugins: {
        "postcss-import": {},
        tailwindcss: {},
        autoprefixer: {},
        "postcss-scope": ".foo",
    },
};

Usage

The default output for all files would look something like this, where .foo is prepended on all rules. However, using CSS comments, you have more control over each file.

.foo .class {
    font-size: 12px;
}

.foo #id {
    font-size: 12px;
}

Ignore rules

Add a comment to specify particular rules that should not be scoped

.foo .class {
    font-size: 12px;
}

/* postcss-scope:ignore */
#id {
    font-size: 12px;
}

Ignore files

Add a comment to specify files that the plugin should ignore

/* postcss-scope:ignore-file */

.class {
    font-size: 12px;
}

#id {
    font-size: 12px;
}

Override global selector

Add a comment to override the selector for a particular file

/* postcss-scope:.bar */

.bar .class {
    font-size: 12px;
}

.bar #id {
    font-size: 12px;
}

postcss-scope's People

Contributors

jackall3n avatar renovate[bot] avatar gbale avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.