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