postcss-preserve-px-fontsize
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

postcss-preserve-px-fontsize

preserve px font-size from postcss-px-to-viewport, only for vw unit.

Requirement

Must set this plugin after postcss-px-to-viewport.

Usage

const postcss = require('postcss');
const preserveFontSize = require('../src/index');
const fs = require('fs');
 
const css = fs.readFileSync('./example/test.css', 'utf8');
 
postcss([preserveFontSize({
    viewportWidth: 750,
    lineHeight: true
})]).process(css).then(rst => {
    console.log(rst.css);
});

input

div {
    font-size: 50vw;
    /* 375px */
    font: bold 4.267vw/50vw "Microsoft Yahei"; 
    /* 32px */
    color: red;
    line-height: 4.267vw;
}

output

div {
    font-size: 375px;
    /* 375px */
    font: bold 32px/375px "Microsoft Yahei"; 
    /* 32px */
    color: red;
    line-height: 32px;
}

Options

Skip a declaration

Maybe you want to use vw for a specified declaration, you can add a comment /* skipvw */ after the declaration.

div {
    font-size: 50vw; /* skipvw */
    /* 375px */
    font: bold 4.267vw/50vw "Microsoft Yahei"; 
    /* 32px */
    color: red;
    line-height: 4.267vw;
}

This will preserve vw for font-size.

output

div {
    font-size: 50vw; /* skipvw */
    /* 375px */
    font: bold 32px/375px "Microsoft Yahei"; 
    /* 32px */
    color: red;
    line-height: 32px;
}

Package Sidebar

Install

npm i postcss-preserve-px-fontsize

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

6.33 kB

Total Files

7

Last publish

Collaborators

  • ta7sudan