Skip to content

Latest commit

 

History

History
181 lines (136 loc) · 3.71 KB

INSTALL.md

File metadata and controls

181 lines (136 loc) · 3.71 KB

Installing PostCSS theme-ui

PostCSS theme-ui runs in all Node environments, with special instructions for:

Node PostCSS CLI Webpack Create React App Gulp Grunt

Node

Add PostCSS theme-ui to your project:

npm install postcss-theme-ui --save-dev

Use PostCSS theme-ui to process your CSS:

const postcssThemeUi = require('postcss-theme-ui');

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

Or use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssThemeUi = require('postcss-theme-ui');

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

PostCSS CLI

Add PostCSS CLI to your project:

npm install postcss-cli --save-dev

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

const postcssThemeUi = require('postcss-theme-ui');

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

Webpack

Add PostCSS Loader to your project:

npm install postcss-loader --save-dev

Use PostCSS theme-ui in your Webpack configuration:

const postcssThemeUi = require('postcss-theme-ui');

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

const reactAppRewirePostcss = require('react-app-rewire-postcss');
const postcssThemeUi = require('postcss-theme-ui');

module.exports = config => reactAppRewirePostcss(config, {
  plugins: () => [
    postcssThemeUi(theme)
  ]
});

Then replace react-scripts calls to react-app-rewired in your package.json:

  "scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-scripts eject"
  }

Gulp

Add Gulp PostCSS to your project:

npm install gulp-postcss --save-dev

Use PostCSS theme-ui in your Gulpfile:

const postcss = require('gulp-postcss');
const postcssThemeUi = require('postcss-theme-ui');

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

Grunt

Add Grunt PostCSS to your project:

npm install grunt-postcss --save-dev

Use PostCSS theme-ui in your Gruntfile:

const postcssThemeUi = require('postcss-theme-ui');

grunt.loadNpmTasks('grunt-postcss');

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