2023-11-09 18:47:11 +01:00

3.5 KiB

Installing PostCSS HWB Function

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

Node PostCSS CLI Webpack Create React App Gulp Grunt

Node

Add PostCSS HWB Function to your project:

npm install postcss @csstools/postcss-hwb-function --save-dev

Use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssHWBFunction = require('@csstools/postcss-hwb-function');

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

PostCSS CLI

Add PostCSS CLI to your project:

npm install postcss-cli --save-dev

Use PostCSS HWB Function in your postcss.config.js configuration file:

const postcssHWBFunction = require('@csstools/postcss-hwb-function');

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

Webpack

Add PostCSS Loader to your project:

npm install postcss-loader --save-dev

Use PostCSS HWB Function in your Webpack configuration:

const postcssHWBFunction = require('@csstools/postcss-hwb-function');

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

const reactAppRewirePostcss = require('react-app-rewire-postcss');
const postcssHWBFunction = require('@csstools/postcss-hwb-function');

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

Gulp

Add Gulp PostCSS to your project:

npm install gulp-postcss --save-dev

Use PostCSS HWB Function in your Gulpfile:

const postcss = require('gulp-postcss');
const postcssHWBFunction = require('@csstools/postcss-hwb-function');

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

Grunt

Add Grunt PostCSS to your project:

npm install grunt-postcss --save-dev

Use PostCSS HWB Function in your Gruntfile:

const postcssHWBFunction = require('@csstools/postcss-hwb-function');

grunt.loadNpmTasks('grunt-postcss');

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