Skip to content

Latest commit

 

History

History
184 lines (137 loc) · 3.8 KB

INSTALL.md

File metadata and controls

184 lines (137 loc) · 3.8 KB

Installing PostCSS Normalize

PostCSS Normalize runs in all Node environments, with special instructions for:

Node PostCSS CLI Webpack Create React App Gulp Grunt

Node

Add PostCSS Normalize to your project:

npm install postcss-normalize --save-dev

Use PostCSS Normalize to process your CSS:

const postcssNormalize = require('postcss-normalize');

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

Or use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssNormalize = require('postcss-normalize');

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

PostCSS CLI

Add PostCSS CLI to your project:

npm install postcss-cli --save-dev

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

const postcssNormalize = require('postcss-normalize');

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

Webpack

Add PostCSS Loader to your project:

npm install postcss-loader --save-dev

Use PostCSS Normalize in your Webpack configuration:

const postcssNormalize = require('postcss-normalize');

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

Create React App

Starting from v3.0.0, Create React App already includes postcss-normalize. To start using it, use the @import-normalize rule:

// index.css

@import-normalize;

If you're using an older version of 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 Normalize in your config-overrides.js file:

const reactAppRewirePostcss = require('react-app-rewire-postcss');
const postcssNormalize = require('postcss-normalize');

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

Gulp

Add Gulp PostCSS to your project:

npm install gulp-postcss --save-dev

Use PostCSS Normalize in your Gulpfile:

const postcss = require('gulp-postcss');
const postcssNormalize = require('postcss-normalize');

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

Grunt

Add Grunt PostCSS to your project:

npm install grunt-postcss --save-dev

Use PostCSS Normalize in your Gruntfile:

const postcssNormalize = require('postcss-normalize');

grunt.loadNpmTasks('grunt-postcss');

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