All Projects → nju33 → postcss-namespace

nju33 / postcss-namespace

Licence: MIT license
PostCSS plugin that prefix a namespace to a selector

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to postcss-namespace

Postcss Sorting
PostCSS plugin to keep rules and at-rules content in order.
Stars: ✭ 438 (+2637.5%)
Mutual labels:  postcss-plugins
Postcss Plugins
The "officially unofficial" consolidated list of PostCSS plugins in a ready-to-use package
Stars: ✭ 107 (+568.75%)
Mutual labels:  postcss-plugins
postcss-stylestats
[Unmainted] PostCSS plugin for StyleStats.
Stars: ✭ 13 (-18.75%)
Mutual labels:  postcss-plugins
Postcss Start To End
PostCSS plugin that lets you control your layout (LTR or RTL) through logical rather than physical rules
Stars: ✭ 18 (+12.5%)
Mutual labels:  postcss-plugins
Postcss Nested Ancestors
👩‍👧‍👦 PostCSS plugin to reference any parent/ancestor selector in nested CSS.
Stars: ✭ 79 (+393.75%)
Mutual labels:  postcss-plugins
Postcss Instagram
📷 PostCSS plugin for using Instagram filters in CSS
Stars: ✭ 111 (+593.75%)
Mutual labels:  postcss-plugins
Postcss Utilities
PostCSS plugin to add a collection of mixins, shortcuts, helpers and tools for your CSS
Stars: ✭ 293 (+1731.25%)
Mutual labels:  postcss-plugins
postcss-gtk
Processes GTK+ CSS into browser CSS
Stars: ✭ 23 (+43.75%)
Mutual labels:  postcss-plugins
Postcss Font Family System Ui
PostCSS plugin to transform W3C CSS font-family: system-ui to a practical font-family list
Stars: ✭ 91 (+468.75%)
Mutual labels:  postcss-plugins
Stylefmt
stylefmt is a tool that automatically formats stylesheets.
Stars: ✭ 2,123 (+13168.75%)
Mutual labels:  postcss-plugins
Stencil Postcss
Autoprefixer plugin for Stencil
Stars: ✭ 19 (+18.75%)
Mutual labels:  postcss-plugins
Postcss At Rules Variables
PostCss plugin to use CSS Custom Properties in at-rule @each, @for, @if, @else and more...
Stars: ✭ 52 (+225%)
Mutual labels:  postcss-plugins
Postcss Aspect Ratio Mini
A PostCSS plugin to fix an element's dimensions to an aspect ratio
Stars: ✭ 123 (+668.75%)
Mutual labels:  postcss-plugins
Postcss Cssnext
`postcss-cssnext` has been deprecated in favor of `postcss-preset-env`.
Stars: ✭ 5,388 (+33575%)
Mutual labels:  postcss-plugins
postcss-if-media
A PostCSS plugin to inline or nest media queries within CSS rules & properties.
Stars: ✭ 35 (+118.75%)
Mutual labels:  postcss-plugins
Autoprefixer
Parse CSS and add vendor prefixes to rules by Can I Use
Stars: ✭ 20,001 (+124906.25%)
Mutual labels:  postcss-plugins
Postcss High Contrast
Create high contrast version of your project with ease.
Stars: ✭ 108 (+575%)
Mutual labels:  postcss-plugins
postcss-clip-path-polyfill
PostCSS plugin which add SVG hack for clip-path property to make it work in Firefox
Stars: ✭ 24 (+50%)
Mutual labels:  postcss-plugins
laggard
Automatically generate CSS fallbacks for legacy browsers, built on PostCSS
Stars: ✭ 23 (+43.75%)
Mutual labels:  postcss-plugins
Rucksack
A little bag of CSS superpowers, built on PostCSS
Stars: ✭ 1,861 (+11531.25%)
Mutual labels:  postcss-plugins

postcss-namespace

npm version Build Status XO code style

PostCSS plugin that prefix a namespace to a selector


Install

npm i postcss-namespace

Usage

Write @prefix atrule to your css file. (e.g. input.css)

.outside {}

@prefix block not(.not-target, /ignore/);

.box {}

.inner .target {}
.inner .not-target {}
.inner .ignore-1 {}
.inner .ignore-2,
.inner .target {}

@prefix ;

.box {}

@prefix block2;

.box {}
&:hover {}
[href^="https"][target="_blank"] {}

@media screen and (min-width: 768px) {
  #media {}
  #media #inner,
  .media .inner.box {}
}

Use this plugin in PostCSS (e.g.)

const fs = require('fs');
const postcss = require('postcss');
const namespace = require('postcss-namespace');

const css = fs.readFileSync('./sample.css', 'utf-8');

// or postcss([namespace.bem])
postcss([namespace({token: '__'})])
  .process(css)
  .then(result => console.log(result.css));

Will get output like following CSS

.outside {}

.block__box {}

.block__inner .block__target {}
.block__inner .not-target {}
.block__inner .ignore-1 {}
.block__inner .ignore-2,
.block__inner .block__target {}

.box {}

.block2__box {}
&:hover {}
[href^="https"][target="_blank"] {}

@media screen and (min-width: 768px) {
  #block2__media {}
  #block2__media #block2__inner,
  .block2__media .block2__inner.block2__box {}
}

AtRule Function

  • not (string|regexp)...
    Specify selector or pattern which Don't want a prefix

Plugin Function

  • namespace.bem
    Same as namespace({token: '__'})

Options

  • token
    Token for consolidate(e.g.) namespace({token: '__'})
    - by default

Run to example

1 Close this

git clone [email protected]:totora0155/postcss-namespace.git

2 Change directory

cd postcss-namespace

3 Install modules

npm install

4 Run to script

cd examples && node postcss.js

Change log

version log
1.1.0 Add bem function. (Alias {token: '__'})
1.0.1 Fix node.nodes
1.0.0 Rewrite with es2015 & Add not func in AtRule
0.2.5 Bug fix for :nth* selector & Revert v0.2.2
0.2.4 Bug fix for pseudo selector
0.2.3 Bug fix (Tag not output after atrule)
0.2.2 Fix, occured error to postcss-selector-not syntax
0.2.0 Change at-rule keyword to @prefix from @namespace #1
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].