JSPM

  • Created
  • Published
  • Downloads 15574942
  • Score
    100M100P100Q225680F
  • License MIT

PostCSS plugin to unwrap nested rules like it Sass does

Package Exports

  • postcss-nested

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (postcss-nested) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

PostCSS Nested Build Status

PostCSS plugin to unwrap nested rules like it Sass does.

.phone {
    &_title {
        width: 500px;
        @media (max-width: 500px) {
            width: auto;
        }
    }
    body.is_dark &_title {
        color: white;
    }
    img {
        display: block;
    }
}

will be processed to:

.phone_title {
    width: 500px;
}
@media (max-width: 500px) {
    .phone_title {
        width: auto;
    }
}
body.is_dark phone_title {
    color: white;
}
.phone img {
    display: block;
}
Sponsored by Evil Martians

Usage

See PostCSS docs for source map options and other special cases.

Grunt

grunt.initConfig({
    postcss: {
        options: {
            processors: [ require('postcss-nested').postcss ]
        },
        dist: {
            src: 'css/*.css'
        }
    }
});

grunt.loadNpmTasks('grunt-postcss');

Gulp

var postcss = require('gulp-postcss');

gulp.task('css', function () {
     return gulp.src('./src/*.css')
        .pipe(postcss([ require('postcss-nested') ]))
        .pipe(gulp.dest('./dest'));
});

Node

var postcss = require('postcss');
var nested  = require('postcss-nested');

var processed = postcss(nested).process(css).css;