A PostCSS plugin that removes duplicates css properties and selector accross multiples css files.
npm install postcss-slash-css
This plugin only supports node v8.0.0 and over.
const postcss = require("postcss");
const slashCSS = require("");
postcss([slashCSS({ targets: "**/*.css" })]);
See PostCSS docs for examples for your environment.
Example with gulp :
const postcss = require('gulp-postcss');
const gulp = require('gulp');
const slashCSS = require("../../index");
const inputFilePath = "../assets/normal.css";
const targetFilePath = "../assets/*.critical.css";
const outputFilePath = "./result.css";
// plugin we will use in postcss
const pluginsUsed = [
slashCSS({ targets: targetFilePath })
];
gulp.task('css', function () {
return gulp.src(inputFilePath)
.pipe(postcss(pluginsUsed))
.pipe(gulp.dest(outputFilePath));
});
- Type:
string
(glob using fast-glob) - Required
CSS files to search duplicates within source file.
- Type:
string
(not case sensitive) - Optional
- Default:
MatchAtleastOne
Can be MatchAtleastOne
or MatchAll
.
If MatchAll
is used, css will be removed only if it is present in ALL targets files.
If MatchAtleastOne
is used, css will be removed when it is present ATLEAST in one of targets css files.
- Type:
boolean
- Optional
- Default: true
if false
two properties are equals even if one has important and the other does not have it.
To test this plugin, just run :
npm test
You can see multiples exemples in the example folder.
This software is released under the terms of the MIT license.