GitXplorerGitXplorer
c

postcss-scopeify

public
1 stars
0 forks
0 issues

Commits

List of commits on branch main.
Unverified
3b165e8369b687a2196e9119ddce321011dcfbbb

Add test for commas

cc0rdyc3p5 committed a year ago
Unverified
687496d3987c238bd66ae4b6363c896eae44a557

Fix module problems

cc0rdyc3p5 committed a year ago
Unverified
607932a0f8946302edc725d5ac1ac4b548fac198

Update version

cc0rdyc3p5 committed a year ago
Unverified
78a32e16b45937cbb5520db5e0454cb7d9f61cb9

Fix typo in readme

cc0rdyc3p5 committed a year ago
Unverified
fd73bb2a7a54a588278a12c757d898ff457ce961

Rename package

cc0rdyc3p5 committed a year ago
Unverified
bacf4393417b0b9500994545493b606c8d77a4dd

Add link to the license in the readme

cc0rdyc3p5 committed a year ago

README

The README file for this repository.

PostCSS-Scopeify

PostCSS-Scopeify is a PostCSS plugin that allows you to scope CSS selectors with a specified prefix, ensuring style isolation and modularity. Prevent selector conflicts and improve maintainability of your CSS with this powerful tool!

Installation

To use PostCSS-Scopeify, first install it via npm or yarn:

npm install postcss postcss-scopeify --save-dev

Testing

npm run test

Usage

To use PostCSS-Scopeify, you'll need to set up PostCSS in your project. Create a postcss.config.js file in the root of your project and add postcss-scopeify to the plugins list.

Here's a basic example of how to use PostCSS-Scopeify:

// postcss.config.js
module.exports = {
    plugins: [
        // Nesting/Import/StylesLibrary PostCSS plugins here...
        require('postcss-scopeify')({
            scope: '.my-scoped-rule ', // Set the prefix for scoping
            exclude: [':root', '.ignore-me'], // Optional: Exclude selectors from scoping
        }),
        // Minification PostCSS plugins here...
    ],
};

OR

// postcss.config.js
module.exports = {
    plugins: {
        // Nesting/Import/StylesLibrary PostCSS plugins here...
        "postcss-scopeify": {
            scope: '.my-scoped-rule ', // Set the prefix for scoping
            exclude: [':root', '.ignore-me'], // Optional: Exclude selectors from scoping
        },
        // Minification PostCSS plugins here...
    }
}

Example 1 - Basic Usage:

/* Input CSS */
.button {
    background-color: #3498db;
    color: #fff;
}

/* Output CSS */
.my-scoped-rule .button {
    background-color: #3498db;
    color: #fff;
}

Example 2 - Excluding Selectors:

/* Input CSS */
.button {
    background-color: #3498db;
    color: #fff;
}

/* Excluded Selector */
.ignore-me {
    display: none;
}

/* Output CSS */
.my-scoped-rule .button {
    background-color: #3498db;
    color: #fff;
}

/* No scoping applied to the excluded selector */
.ignore-me {
    display: none;
}

Example 3 - State Selectors:

/* Input CSS */
.button {
    background-color: #3498db;
    color: #fff;
}

.button:hover {
    background-color: #2980b9;
}

/* Output CSS */
.my-scoped-rule .button {
    background-color: #3498db;
    color: #fff;
}

.my-scoped-rule .button:hover {
    background-color: #2980b9;
}

Example 4 - Chained Selectors:

/* Input CSS */
.header .nav .link {
    color: #333;
}

/* Output CSS */
.my-scoped-rule .header .nav .link {
    color: #333;
}

Example 5 - Media Queries:

/* Input CSS */
@media screen and (max-width: 1240px) {
    .container {
        width: 100%;
    }

    .container .item {
        width: 100%;
    }

    .container .item .item-content {
        width: 100%;
    }
}

/* Output CSS */
@media screen and (max-width: 1240px) {
    .my-scoped-rule .container {
        width: 100%;
    }

    .my-scoped-rule .container .item {
        width: 100%;
    }

    .my-scoped-rule .container .item .item-content {
        width: 100%;
    }
}

Contributing

Contributions are welcome! If you encounter any issues or have suggestions for improvements, feel free to create an issue or submit a pull request.

License

This project is licensed under the MIT License.