| 1 | # Installing PostCSS HWB Function
|
|---|
| 2 |
|
|---|
| 3 | [PostCSS HWB Function] runs in all Node environments, with special instructions for:
|
|---|
| 4 |
|
|---|
| 5 | | [Node](#node) | [PostCSS CLI](#postcss-cli) | [Webpack](#webpack) | [Create React App](#create-react-app) | [Gulp](#gulp) | [Grunt](#grunt) |
|
|---|
| 6 | | --- | --- | --- | --- | --- | --- |
|
|---|
| 7 |
|
|---|
| 8 | ## Node
|
|---|
| 9 |
|
|---|
| 10 | Add [PostCSS HWB Function] to your project:
|
|---|
| 11 |
|
|---|
| 12 | ```bash
|
|---|
| 13 | npm install postcss @csstools/postcss-hwb-function --save-dev
|
|---|
| 14 | ```
|
|---|
| 15 |
|
|---|
| 16 | Use it as a [PostCSS] plugin:
|
|---|
| 17 |
|
|---|
| 18 | ```js
|
|---|
| 19 | const postcss = require('postcss');
|
|---|
| 20 | const postcssHWBFunction = require('@csstools/postcss-hwb-function');
|
|---|
| 21 |
|
|---|
| 22 | postcss([
|
|---|
| 23 | postcssHWBFunction(/* pluginOptions */)
|
|---|
| 24 | ]).process(YOUR_CSS /*, processOptions */);
|
|---|
| 25 | ```
|
|---|
| 26 |
|
|---|
| 27 | ## PostCSS CLI
|
|---|
| 28 |
|
|---|
| 29 | Add [PostCSS CLI] to your project:
|
|---|
| 30 |
|
|---|
| 31 | ```bash
|
|---|
| 32 | npm install postcss-cli @csstools/postcss-hwb-function --save-dev
|
|---|
| 33 | ```
|
|---|
| 34 |
|
|---|
| 35 | Use [PostCSS HWB Function] in your `postcss.config.js` configuration file:
|
|---|
| 36 |
|
|---|
| 37 | ```js
|
|---|
| 38 | const postcssHWBFunction = require('@csstools/postcss-hwb-function');
|
|---|
| 39 |
|
|---|
| 40 | module.exports = {
|
|---|
| 41 | plugins: [
|
|---|
| 42 | postcssHWBFunction(/* pluginOptions */)
|
|---|
| 43 | ]
|
|---|
| 44 | }
|
|---|
| 45 | ```
|
|---|
| 46 |
|
|---|
| 47 | ## Webpack
|
|---|
| 48 |
|
|---|
| 49 | _Webpack version 5_
|
|---|
| 50 |
|
|---|
| 51 | Add [PostCSS Loader] to your project:
|
|---|
| 52 |
|
|---|
| 53 | ```bash
|
|---|
| 54 | npm install postcss-loader @csstools/postcss-hwb-function --save-dev
|
|---|
| 55 | ```
|
|---|
| 56 |
|
|---|
| 57 | Use [PostCSS HWB Function] in your Webpack configuration:
|
|---|
| 58 |
|
|---|
| 59 | ```js
|
|---|
| 60 | module.exports = {
|
|---|
| 61 | module: {
|
|---|
| 62 | rules: [
|
|---|
| 63 | {
|
|---|
| 64 | test: /\.css$/i,
|
|---|
| 65 | use: [
|
|---|
| 66 | "style-loader",
|
|---|
| 67 | {
|
|---|
| 68 | loader: "css-loader",
|
|---|
| 69 | options: { importLoaders: 1 },
|
|---|
| 70 | },
|
|---|
| 71 | {
|
|---|
| 72 | loader: "postcss-loader",
|
|---|
| 73 | options: {
|
|---|
| 74 | postcssOptions: {
|
|---|
| 75 | plugins: [
|
|---|
| 76 | [
|
|---|
| 77 | "@csstools/postcss-hwb-function",
|
|---|
| 78 | {
|
|---|
| 79 | // Options
|
|---|
| 80 | },
|
|---|
| 81 | ],
|
|---|
| 82 | ],
|
|---|
| 83 | },
|
|---|
| 84 | },
|
|---|
| 85 | },
|
|---|
| 86 | ],
|
|---|
| 87 | },
|
|---|
| 88 | ],
|
|---|
| 89 | },
|
|---|
| 90 | };
|
|---|
| 91 | ```
|
|---|
| 92 |
|
|---|
| 93 | ## Create React App
|
|---|
| 94 |
|
|---|
| 95 | Add [React App Rewired] and [React App Rewire PostCSS] to your project:
|
|---|
| 96 |
|
|---|
| 97 | ```bash
|
|---|
| 98 | npm install react-app-rewired react-app-rewire-postcss @csstools/postcss-hwb-function --save-dev
|
|---|
| 99 | ```
|
|---|
| 100 |
|
|---|
| 101 | Use [React App Rewire PostCSS] and [PostCSS HWB Function] in your
|
|---|
| 102 | `config-overrides.js` file:
|
|---|
| 103 |
|
|---|
| 104 | ```js
|
|---|
| 105 | const reactAppRewirePostcss = require('react-app-rewire-postcss');
|
|---|
| 106 | const postcssHWBFunction = require('@csstools/postcss-hwb-function');
|
|---|
| 107 |
|
|---|
| 108 | module.exports = config => reactAppRewirePostcss(config, {
|
|---|
| 109 | plugins: () => [
|
|---|
| 110 | postcssHWBFunction(/* pluginOptions */)
|
|---|
| 111 | ]
|
|---|
| 112 | });
|
|---|
| 113 | ```
|
|---|
| 114 |
|
|---|
| 115 | ## Gulp
|
|---|
| 116 |
|
|---|
| 117 | Add [Gulp PostCSS] to your project:
|
|---|
| 118 |
|
|---|
| 119 | ```bash
|
|---|
| 120 | npm install gulp-postcss @csstools/postcss-hwb-function --save-dev
|
|---|
| 121 | ```
|
|---|
| 122 |
|
|---|
| 123 | Use [PostCSS HWB Function] in your Gulpfile:
|
|---|
| 124 |
|
|---|
| 125 | ```js
|
|---|
| 126 | const postcss = require('gulp-postcss');
|
|---|
| 127 | const postcssHWBFunction = require('@csstools/postcss-hwb-function');
|
|---|
| 128 |
|
|---|
| 129 | gulp.task('css', function () {
|
|---|
| 130 | var plugins = [
|
|---|
| 131 | postcssHWBFunction(/* pluginOptions */)
|
|---|
| 132 | ];
|
|---|
| 133 |
|
|---|
| 134 | return gulp.src('./src/*.css')
|
|---|
| 135 | .pipe(postcss(plugins))
|
|---|
| 136 | .pipe(gulp.dest('.'));
|
|---|
| 137 | });
|
|---|
| 138 | ```
|
|---|
| 139 |
|
|---|
| 140 | ## Grunt
|
|---|
| 141 |
|
|---|
| 142 | Add [Grunt PostCSS] to your project:
|
|---|
| 143 |
|
|---|
| 144 | ```bash
|
|---|
| 145 | npm install grunt-postcss @csstools/postcss-hwb-function --save-dev
|
|---|
| 146 | ```
|
|---|
| 147 |
|
|---|
| 148 | Use [PostCSS HWB Function] in your Gruntfile:
|
|---|
| 149 |
|
|---|
| 150 | ```js
|
|---|
| 151 | const postcssHWBFunction = require('@csstools/postcss-hwb-function');
|
|---|
| 152 |
|
|---|
| 153 | grunt.loadNpmTasks('grunt-postcss');
|
|---|
| 154 |
|
|---|
| 155 | grunt.initConfig({
|
|---|
| 156 | postcss: {
|
|---|
| 157 | options: {
|
|---|
| 158 | processors: [
|
|---|
| 159 | postcssHWBFunction(/* pluginOptions */)
|
|---|
| 160 | ]
|
|---|
| 161 | },
|
|---|
| 162 | dist: {
|
|---|
| 163 | src: '*.css'
|
|---|
| 164 | }
|
|---|
| 165 | }
|
|---|
| 166 | });
|
|---|
| 167 | ```
|
|---|
| 168 |
|
|---|
| 169 | [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
|
|---|
| 170 | [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
|
|---|
| 171 | [PostCSS]: https://github.com/postcss/postcss
|
|---|
| 172 | [PostCSS CLI]: https://github.com/postcss/postcss-cli
|
|---|
| 173 | [PostCSS Loader]: https://github.com/postcss/postcss-loader
|
|---|
| 174 | [PostCSS HWB Function]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-hwb-function
|
|---|
| 175 | [React App Rewire PostCSS]: https://github.com/csstools/react-app-rewire-postcss
|
|---|
| 176 | [React App Rewired]: https://github.com/timarney/react-app-rewired
|
|---|