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