Git Product home page Git Product logo

prefixify-css's Introduction

prefixify-css

Reads a CSS file meant for 'global context' and prefixes each selector with a specified selector, wrapping the remainder in :global()

.SomeLibrary .wrapper {
  width: 100%;
}
.SomeLibrary-blah li:nth-child(5) {
  opacity: 0.5;
}

/* Becomes */

.myPrefix :global(.SomeLibrary .wrapper) {
  width: 100%;
}
.myPrefix :global(.SomeLibrary-blah li:nth-child(5)) {
  opacity: 0.5;
}

This is useful when using CSS Modules and you want to include something like CodeMirror, Leaflet and other libraries which has CSS which are globally scoped, but you want to at the very least contain it to within one of your classes.

Installation

As a CLI tool:

npm install -g prefixify-css

or, if you want to use it programatically:

npm install prefixify-css

Usage (CLI)

$ prefixify

  prefixify-css: Reads a CSS file meant for 'global context' and prefixes each selector with a specified selector, wrapping the remainder in :global()

  The result is written to stdout.

  Usage
    $ prefixify <input> <selector>

  Examples
    $ prefixify leaflet.css '.leafletInput' > prefixed.css
    $ prefixify - '.leafletInput' < cat /path/to/leaflet.css

Alternatively, you can run it through npx without even having to install it:

$ npx prefixify-css myFile.css .mySelector

Usage (JavaScript API)

const prefixify = require('prefixify-css')

prefix({
  content: '.CodeMirror { width: 100%; }',
  selector: '.myClass',
})
  .then((result) => {
    // .myClass :global(.CodeMirror) { width: 100%; }
    console.log(result)
  })
  .catch((error) => {
    console.error(error)
  })

License

MIT © Espen Hovlandsdal

prefixify-css's People

Contributors

rexxars avatar

Watchers

 avatar James Cloos 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.