4.2 KiB
Installing PostCSS HWB Function
PostCSS HWB Function runs in all Node environments, with special instructions for:
Node
Add PostCSS HWB Function to your project:
npm install postcss @csstools/postcss-hwb-function --save-dev
Use it as a PostCSS plugin:
// commonjs
const postcss = require('postcss');
const postcssHWBFunction = require('@csstools/postcss-hwb-function');
postcss([
postcssHWBFunction(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
// esm
import postcss from 'postcss';
import postcssHWBFunction from '@csstools/postcss-hwb-function';
postcss([
postcssHWBFunction(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
PostCSS CLI
Add PostCSS CLI to your project:
npm install postcss-cli @csstools/postcss-hwb-function --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 */)
]
}
PostCSS Load Config
If your framework/CLI supports postcss-load-config
.
npm install @csstools/postcss-hwb-function --save-dev
package.json
:
{
"postcss": {
"plugins": {
"@csstools/postcss-hwb-function": {}
}
}
}
.postcssrc.json
:
{
"plugins": {
"@csstools/postcss-hwb-function": {}
}
}
See the README of postcss-load-config
for more usage options.
Webpack
Webpack version 5
Add PostCSS Loader to your project:
npm install postcss-loader @csstools/postcss-hwb-function --save-dev
Use PostCSS HWB Function in your Webpack configuration:
module.exports = {
module: {
rules: [
{
test: /\.css$/i,
use: [
"style-loader",
{
loader: "css-loader",
options: { importLoaders: 1 },
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
// Other plugins,
[
"@csstools/postcss-hwb-function",
{
// Options
},
],
],
},
},
},
],
},
],
},
};
Next.js
Read the instructions on how to customize the PostCSS configuration in Next.js
npm install @csstools/postcss-hwb-function --save-dev
Use PostCSS HWB Function in your postcss.config.json
file:
{
"plugins": [
"@csstools/postcss-hwb-function"
]
}
{
"plugins": [
[
"@csstools/postcss-hwb-function",
{
// Optionally add plugin options
}
]
]
}
Gulp
Add Gulp PostCSS to your project:
npm install gulp-postcss @csstools/postcss-hwb-function --save-dev
Use PostCSS HWB Function in your Gulpfile:
const postcss = require('gulp-postcss');
const postcssHWBFunction = require('@csstools/postcss-hwb-function');
gulp.task('css', function () {
var plugins = [
postcssHWBFunction(/* pluginOptions */)
];
return gulp.src('./src/*.css')
.pipe(postcss(plugins))
.pipe(gulp.dest('.'));
});
Grunt
Add Grunt PostCSS to your project:
npm install grunt-postcss @csstools/postcss-hwb-function --save-dev
Use PostCSS HWB Function in your Gruntfile:
const postcssHWBFunction = require('@csstools/postcss-hwb-function');
grunt.loadNpmTasks('grunt-postcss');
grunt.initConfig({
postcss: {
options: {
processors: [
postcssHWBFunction(/* pluginOptions */)
]
},
dist: {
src: '*.css'
}
}
});