misc-tjund/postcss-explore/INSTALL.md

3.7 KiB

Installing PostCSS postcss-explore

PostCSS postcss-explore runs in all Node environments, with special instructions for:

Node PostCSS CLI Webpack Create React App Gulp Grunt

Node

Add PostCSS postcss-explore to your project:

npm install postcss-postcss-explore --save-dev

Use PostCSS postcss-explore to process your CSS:

const postcssPostcssExplore = require('postcss-postcss-explore');

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

Or use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssPostcssExplore = require('postcss-postcss-explore');

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

PostCSS CLI

Add PostCSS CLI to your project:

npm install postcss-cli --save-dev

Use PostCSS postcss-explore in your postcss.config.js configuration file:

const postcssPostcssExplore = require('postcss-postcss-explore');

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

Webpack

Add PostCSS Loader to your project:

npm install postcss-loader --save-dev

Use PostCSS postcss-explore in your Webpack configuration:

const postcssPostcssExplore = require('postcss-postcss-explore');

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader',
          { loader: 'css-loader', options: { importLoaders: 1 } },
          { loader: 'postcss-loader', options: {
            ident: 'postcss',
            plugins: () => [
              postcssPostcssExplore(/* 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 postcss-explore in your config-overrides.js file:

const reactAppRewirePostcss = require('react-app-rewire-postcss');
const postcssPostcssExplore = require('postcss-postcss-explore');

module.exports = config => reactAppRewirePostcss(config, {
  plugins: () => [
    postcssPostcssExplore(/* pluginOptions */)
  ]
});

Gulp

Add Gulp PostCSS to your project:

npm install gulp-postcss --save-dev

Use PostCSS postcss-explore in your Gulpfile:

const postcss = require('gulp-postcss');
const postcssPostcssExplore = require('postcss-postcss-explore');

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

Grunt

Add Grunt PostCSS to your project:

npm install grunt-postcss --save-dev

Use PostCSS postcss-explore in your Gruntfile:

const postcssPostcssExplore = require('postcss-postcss-explore');

grunt.loadNpmTasks('grunt-postcss');

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