
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
postcss-plugin-px2em
Advanced tools
A plugin for PostCSS that generates em units from pixel units.
$ npm i --save postcss-plugin-px2em
// input
h1 {
margin: 0 0 20px;
font-size: 32px;
line-height: 1.2;
letter-spacing: 1px;
}
// output
h1 {
margin: 0 0 0.2em;
font-size: 0.32em;
line-height: 1.2;
letter-spacing: 0.01em;
}
import { writeFile, readFileSync } from 'fs';
import postcss from 'postcss';
import pxtorem from 'postcss-plugin-px2em';
const css = readFileSync('/path/to/test.css', 'utf8');
const options = {
replace: false,
};
const processedCss = postcss(pxtorem(options)).process(css).css;
writeFile('/path/to/test.rem.css', processedCss, err => {
if (err) throw err;
console.log('Rem file written.');
});
import px2em from 'postcss-plugin-px2em';
const px2emOpts = {
......
};
export default {
module: {
loaders: [
{
test: /\.css$/,
loader: 'style-loader!css-loader!postcss-loader',
},
],
},
postcss: [px2em(px2emOpts)],
}
webpack.connfig.js
import webpack from 'atool-build/lib/webpack';
import px2em from 'postcss-plugin-px2em';
export default webpackConfig => {
const px2emOpts = {
......
};
webpackConfig.postcss.push(px2em(px2emOpts));
return webpackConfig;
};
Default:
{
rootValue: 100,
unitPrecision: 5,
propWhiteList: [],
propBlackList: [],
exclude:false,
selectorBlackList: [],
ignoreIdentifier: false,
replace: true,
mediaQuery: false,
minPixelValue: 0
}
rootValue (Number|Object) The root element font size. Default is 100.
{ px: 50, rpx: 100 }, it will
replace rpx to 1/100 rem , and px to 1/50 rem.unitPrecision (Number) The decimal numbers to allow the REM units to grow to.propWhiteList (Array) The properties that can change from px to rem.
propBlackList (Array) The properties that should not change from px to rem.
exclude (Reg) a way to exclude some folder,eg. /(node_module)/.selectorBlackList (Array) The selectors to ignore and leave as px.
['body'] will match .body-class[/^body$/] will match body but not .bodyignoreIdentifier (Boolean/String) a way to have a single property ignored, when ignoreIdentifier enabled, then replace would be set to true automatically.replace (Boolean) replaces rules containing rems instead of adding fallbacks.mediaQuery (Boolean) Allow px to be converted in media queries.minPixelValue (Number) Set the minimum pixel value to replace.MIT
FAQs
A plugin for PostCSS that generates em units from multi units.
The npm package postcss-plugin-px2em receives a total of 7 weekly downloads. As such, postcss-plugin-px2em popularity was classified as not popular.
We found that postcss-plugin-px2em 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
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.