
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
postcss-unit-processor
Advanced tools
PostCSS plugin to process css unit.
$ npm install postcss postcss-unit-processor --save-dev
Use the processor function provided by the user to process the CSS unit. The default processor function is not to do any processing.
var fs = require('fs');
var postcss = require('postcss');
var unitProcessor = require('postcss-unit-processor');
var css = fs.readFileSync('main.css', 'utf8');
var options = {
processor: (value, unit) => {
if (unit === 'px') {
return value / 2;
}
}
};
var processedCss = postcss(unitProcessor(options)).process(css).css;
fs.writeFile('main-new.css', processedCss, function (err) {
if (err) {
throw err;
}
console.log('New file written.');
});
Type: Object | Null
Default:
{
processor: (value) => value,
unitPrecision: 5,
propList: ['*'],
selectorBlackList: [],
replace: true,
mediaQuery: false,
exclude: /node_modules/i,
customUnitList: []
}
processor
(Function) css unit processing function.
value
of the object replaces the value, and the unit
replaces the name.unitPrecision
(Number) The decimal numbers to allow the processed units to grow to.propList
(Array) The properties that can be changed by the processor function.
*
to enable all properties. Example: ['*']
*
at the start or end of a word. (['*position*']
will match background-position-y
)!
to not match a property. Example: ['*', '!letter-spacing']
['*', '!font*']
selectorBlackList
(Array) The selectors to ignore.
['body']
will match .body-class
[/^body$/]
will match body
but not .body
replace
(Boolean) Replace rules instead of adding fallbacks.mediaQuery
(Boolean) Allow processor function in media queries.exclude
(String, Regexp, Function) The file path to ignore.
'exclude'
will match \project\postcss-unit-processor\exclude\path
/exclude/i
will match \project\postcss-unit-processor\exclude\path
function (file) { return file.indexOf('exclude') !== -1; }
customUnitList
(Array) List of custom units to process in addition to default units.
['dp', 'rpx']
).px
, rem
, vw
, etc.var gulp = require('gulp');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var unitProcessor = require('postcss-unit-processor');
gulp.task('css', function () {
var processors = [
autoprefixer({
browsers: 'last 1 version'
}),
unitProcessor({
processor: (value, unit) => {
if (unit === 'px') {
return value / 2;
}
}
})
];
return gulp.src(['build/css/**/*.css'])
.pipe(postcss(processors))
.pipe(gulp.dest('build/css'));
});
// input
h1 {
margin: 0 0 20px;
font-size: 32px;
line-height: 1.2;
letter-spacing: 1px;
}
// output
h1 {
margin: 0 0 10px;
font-size: 16px;
line-height: 1.2;
letter-spacing: 0.5px;
}
FAQs
PostCSS plugin to process css unit.
The npm package postcss-unit-processor receives a total of 226 weekly downloads. As such, postcss-unit-processor popularity was classified as not popular.
We found that postcss-unit-processor demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.