https://github.com/csstools/postcss-to-nest
Transform unnested CSS into nested CSS
https://github.com/csstools/postcss-to-nest
Last synced: 11 months ago
JSON representation
Transform unnested CSS into nested CSS
- Host: GitHub
- URL: https://github.com/csstools/postcss-to-nest
- Owner: csstools
- License: other
- Archived: true
- Created: 2016-01-26T12:45:49.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-01-26T12:59:06.000Z (about 10 years ago)
- Last Synced: 2025-04-21T21:38:50.033Z (11 months ago)
- Language: JavaScript
- Homepage: https://jonathantneal.github.io/postcss-to-nest/
- Size: 61.5 KB
- Stars: 8
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# CSS To Nest
[![NPM Version][npm-img]][npm] [![Build Status][ci-img]][ci]
[CSS To Nest] transforms unnested CSS into nested CSS, following the [CSS Nesting Module] specification. This might be helpful for updating a project with a single file of legacy CSS.
```css
/* before */
.foo .bar {
color: blue;
}
.foo .bar .pre.mon {
color: white;
}
.foo .bar .pre {
color: red;
}
/* after */
.foo {
@nest & .bar {
color: blue;
@nest & .pre {
color: red;
@nest &.mon {
color: white;
}
}
}
}
```
## Usage
Add [CSS To Nest] to your build tool:
```bash
npm install postcss-to-nest --save-dev
```
#### Node
```js
require('postcss-to-nest').process(YOUR_CSS, { /* options */ });
```
#### PostCSS
Add [PostCSS] to your build tool:
```bash
npm install postcss --save-dev
```
Load [CSS To Nest] as a PostCSS plugin:
```js
postcss([
require('postcss-to-nest')({ /* options */ })
]).process(YOUR_CSS, /* options */);
```
#### Gulp
Add [Gulp PostCSS] to your build tool:
```bash
npm install gulp-postcss --save-dev
```
Enable [CSS To Nest] within your Gulpfile:
```js
var postcss = require('gulp-postcss');
gulp.task('css', function () {
return gulp.src('./src/*.css').pipe(
postcss([
require('postcss-to-nest')({ /* options */ })
])
).pipe(
gulp.dest('.')
);
});
```
#### Grunt
Add [Grunt PostCSS] to your build tool:
```bash
npm install grunt-postcss --save-dev
```
Enable [CSS To Nest] within your Gruntfile:
```js
grunt.loadNpmTasks('grunt-postcss');
grunt.initConfig({
postcss: {
options: {
use: [
require('postcss-to-nest')({ /* options */ })
]
},
dist: {
src: '*.css'
}
}
});
```
[ci]: https://travis-ci.org/jonathantneal/postcss-to-nest
[ci-img]: https://img.shields.io/travis/jonathantneal/postcss-to-nest.svg
[npm]: https://www.npmjs.com/package/postcss-to-nest
[npm-img]: https://img.shields.io/npm/v/postcss-to-nest.svg
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
[PostCSS]: https://github.com/postcss/postcss
[CSS Nesting Module]: https://tabatkins.github.io/specs/css-nesting/
[CSS To Nest]: https://github.com/jonathantneal/postcss-to-nest