
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
postcss-comments
Advanced tools
PostCSS plugin to prepend and append comments to CSS rules.
Some PostCSS plugins require to add comments to the CSS code to be able to perform their work (e.g. RTLCSS or PostCSS RTLCSS). But if the CSS code is coming from a third-party library or a CSS-in-JS framework it is impossible to modify the CSS source to add comments. In these cases, postcss-comments
could be helpful to prepend or append comments to CSS rules selecting them using strings or regular expressions.
npm install postcss-comments --save-dev
yarn add postcss-comments -D
const postcss = require('postcss');
const postcssComments = require('postcss-comments');
const result = postcss([
postcssComments({
rulesMatchers: [
/* rulesMatchers */
]
})
]).process(cssInput);
const commentedCSS = result.css;
import postcss from 'postcss';
import postcssComments from 'postcss-comments';
const result = postcss([
postcssComments({
rulesMatchers: [
/* rulesMatchers */
]
})
]).process(cssInput);
const commentedCSS = result.css;
rules: [
{
test: /\.css$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
postcssComments({
rulesMatchers: [
/* rulesMatchers */
]
})
]
}
}
}
]
}
]
rulesMatchers
consist on an array of objects, each one describing one matcher.
{
matcher: string | RegExp | (string | RegExp)[];
prepend?: string;
append?: string;
}
.test1, .test2 {
color: #666;
padding-right: 20px;
width: 100%;
}
.link {
color: red;
}
.link:hover {
color: red;
}
.link:visited {
color: red;
}
.test-class {
text-align: left;
height: 100px;
}
String matchers will match a rule if the entire selector of the rule matches exactly with the string.
postcssComments({
rulesMatchers: [
{
matcher: ['.link', '.test-class'],
prepend: 'Using an array of string matchers'
},
{
matcher: '.link:visited',
append: 'Using a unique string matcher'
}
]
})
.test1, .test2 {
color: #666;
padding-right: 20px;
width: 100%;
}
/* Using an array of string matchers */
.link {
color: red;
}
.link:hover {
color: red;
}
.link:visited {
color: red;
}
/* Using a unique string matcher */
/* Using an array of string matchers */
.test-class {
text-align: left;
height: 100px;
}
Regular Expressions matchers are more flexible. They allow one to match rules without specifing exactly the string of their selectors using a Regular Expression pattern instead.
postcssComments({
rulesMatchers: [
{
matcher: [/^\.test\d+/, /^\.link:\w+$/],
prepend: 'Using an array of RegExp matchers'
},
{
matcher: /\.test-\w+$/,
append: 'Using a single regular expression'
}
]
})
/* Using an array of RegExp matchers */
.test1, .test2 {
color: #666;
padding-right: 20px;
width: 100%;
}
.link {
color: red;
}
/* Using an array of RegExp matchers */
.link:hover {
color: red;
}
/* Using an array of RegExp matchers */
.link:visited {
color: red;
}
.test-class {
text-align: left;
height: 100px;
}
/* Using a single regular expression */
append
or prepend
comments are inserted and it doesn‘t continue checking the next matchers on the array.[1.0.0] - 2023-08-17
FAQs
Postcss plugin to prepend or append comments to CSS rules
The npm package postcss-comments receives a total of 2 weekly downloads. As such, postcss-comments popularity was classified as not popular.
We found that postcss-comments demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.