1. postcss-flexible
flexible transformer for flexible
postcss-flexible
Package: postcss-flexible
Created by: crossjs
Last modified: Fri, 24 Jun 2022 09:58:23 GMT
Version: 0.5.5
License: MIT
Downloads: 22
Repository: https://github.com/crossjs/postcss-flexible

Install

npm install postcss-flexible
yarn add postcss-flexible

postcss-flexible

This is a postcss plugin for translating dpr(...), rem(...), url(...). Similar to px2rem, but using custom function istead of comments for syntax.

Travis
Coveralls
dependencies
devDependency Status
NPM version

Usage

Webpack

 module.exports = {
  module: {
    loaders: [
      {
        test: /\.css$/,
        loader: "style-loader!css-loader!postcss-loader"
      }
    ]
  },
  postcss: function() {
    // remUnit defaults to 75
    return [require('postcss-flexible')({remUnit: 75})]
  }
}

Example

Before processing:

 .selector {
  font-size: dpr(32px);
  width: rem(75px);
  line-height: 3;
  /* replace all @[1-3]x in urls: `/a/@2x/x.png`, `/a@2x/x.png` or `/a/[email protected]` */
  background-image: url(/images/[email protected]);
}

After processing:

 .selector {
  width: 1rem;
  line-height: 3;
}

[data-dpr="1"] .selector {
  font-size: 16px;
  background-image: url(/images/[email protected]);
}

[data-dpr="2"] .selector {
  font-size: 32px;
  background-image: url(/images/[email protected]);
}

[data-dpr="3"] .selector {
  font-size: 48px;
  background-image: url(/images/[email protected]);
}

options

  • desktop: boolean, default false
  • baseDpr: number, default 2
  • remUnit: number, default 75
  • remPrecision: number, default 6
  • addPrefixToSelector: function
  • dprList: array, default [3, 2, 1]
  • fontGear: array, default [-1, 0, 1, 2, 3, 4]
  • enableFontSetting: boolean, default false
  • addFontSizeToSelector: function
  • outputCSSFile: function

Change Log

0.5.0

  • add: generate different css files with fontGear
  • support custom fontGear
  • support custom enableFontSetting
  • support custom addFontSizeToSelector
  • support custom outputCSSFile

0.4.0

  • support custom dprList

0.3.0

  • add option desktop and addPrefixToSelector

0.1.0

  • handle url()

0.0.3

  • add dpr() and rem()

0.0.0

  • First release.

License

MIT

Dependencies

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin