
Security News
n8n Tops 2025 JavaScript Rising Stars as Workflow Platforms Gain Momentum
n8n led JavaScript Rising Stars 2025 by a wide margin, with workflow platforms seeing the largest growth across categories.
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.');
});
// Only process rem units
unitProcessor({
processor: (value, unit) => value,
unitList: ['rem']
})
// Process all units except rem
unitProcessor({
processor: (value, unit) => value,
unitList: ['!rem']
})
// Process only rem and px units
unitProcessor({
processor: (value, unit) => value,
unitList: ['rem', 'px']
})
Type: Object | Null
Default:
{
processor: (value) => value,
unitPrecision: 5,
propList: ['*'],
unitList: ['*'],
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.unitList (Array) The units that can be changed by the processor function.
* to enable all units. Example: ['*']! to not match a unit. Example: ['*', '!rem']['rem', 'px', 'vw']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 .bodyreplace (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\pathfunction (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 1,822 weekly downloads. As such, postcss-unit-processor popularity was classified as 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
n8n led JavaScript Rising Stars 2025 by a wide margin, with workflow platforms seeing the largest growth across categories.

Security News
The U.S. government is rolling back software supply chain mandates, shifting from mandatory SBOMs and attestations to a risk-based approach.

Security News
crates.io adds a Security tab backed by RustSec advisories and narrows trusted publishing paths to reduce common CI publishing risks.