Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Latest commit

 

History

History
182 lines (135 loc) · 3.73 KB

INSTALL.md

File metadata and controls

182 lines (135 loc) · 3.73 KB

Installing PostCSS Nesting

PostCSS Nesting runs in all Node environments and Deno, with special instructions for:

Node PostCSS CLI Webpack Create React App Gulp Grunt Deno

Node

Add PostCSS Nesting to your project:

npm install postcss-nesting --save-dev

Use PostCSS Nesting to process your CSS:

import postcssNesting from 'postcss-nesting';

postcssNesting.process(YOUR_CSS /*, processOptions, pluginOptions */);

Or use it as a PostCSS plugin:

import postcss from 'postcss';
import postcssNesting from 'postcss-nesting';

postcss([
  postcssNesting(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);

PostCSS CLI

Add PostCSS CLI to your project:

npm install postcss-cli --save-dev

Use PostCSS Nesting in your postcss.config.js configuration file:

const postcssNesting = require('postcss-nesting');

module.exports = {
  plugins: [
    postcssNesting(/* pluginOptions */)
  ]
}

Webpack

Add PostCSS Loader to your project:

npm install postcss-loader --save-dev

Use PostCSS Nesting in your Webpack configuration:

import postcssNesting from 'postcss-nesting';

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader',
          { loader: 'css-loader', options: { importLoaders: 1 } },
          { loader: 'postcss-loader', options: {
            ident: 'postcss',
            plugins: () => [
              postcssNesting(/* pluginOptions */)
            ]
          } }
        ]
      }
    ]
  }
}

Create React App

Add React App Rewired and React App Rewire PostCSS to your project:

npm install react-app-rewired react-app-rewire-postcss --save-dev

Use React App Rewire PostCSS and PostCSS Nesting in your config-overrides.js file:

import reactAppRewirePostcss from 'react-app-rewire-postcss';
import postcssNesting from 'postcss-nesting';

export default config => reactAppRewirePostcss(config, {
  plugins: () => [
    postcssNesting(/* pluginOptions */)
  ]
});

Gulp

Add Gulp PostCSS to your project:

npm install gulp-postcss --save-dev

Use PostCSS Nesting in your Gulpfile:

import postcss from 'gulp-postcss';
import postcssNesting from 'postcss-nesting';

gulp.task('css', () => gulp.src('./src/*.css').pipe(
  postcss([
    postcssNesting(/* pluginOptions */)
  ])
).pipe(
  gulp.dest('.')
));

Grunt

Add Grunt PostCSS to your project:

npm install grunt-postcss --save-dev

Use PostCSS Nesting in your Gruntfile:

import postcssNesting from 'postcss-nesting';

grunt.loadNpmTasks('grunt-postcss');

grunt.initConfig({
  postcss: {
    options: {
      use: [
       postcssNesting(/* pluginOptions */)
      ]
    },
    dist: {
      src: '*.css'
    }
  }
});

Deno

You can also use PostCSS Nesting on Deno:

import postcss from "https://deno.land/x/postcss/mod.js";
import postcssNesting from "https://deno.land/x/postcss_nesting/mod.js";

await postcss([postcssNesting]).process(YOUR_CSS /*, processOptions */);