Giter Club home page Giter Club logo

postcss-rfs-autopilot's Introduction

PostCSS RFS Autopilot terminal screenshot

PostCSS RFS Autopilot

Maintainability Test Coverage Known Vulnerabilities Codacy Badge

A PostCSS plugin that automagically mark your CSS up with rfs() for RFS, helping you achieve a responsive layout efficiently and consistently.

/* Original Input */
.foo {
    font-size: 4em;
}
/* After the transformation of RFS Autopilot but before RFS*/
.foo {
  font-size: rfs(4em);
}
/* After the transformation of RFS*/
.foo {
  font-size: calc(1.525rem + 3.3vw);
}

@media (min-width: 1200px) {
  .foo {
    font-size: 4rem;
  }
}

Problem

RFS is a great unit resizing engine that helps you build responsive CSS layout, but writing rfs() everywhere manually is a pain in the ass.

With this plugin, you just need to declare rules you want to apply rfs() to, and it will do the heavy-lifting for you.

Made in Hong Kong ๐Ÿ†“ ๐Ÿ†“

This plugin is made with love by a Hong Konger.

Installation

As this plugin is a PostCSS plugin, you need to install and set up PostCSS first before use it. If you haven't used PostCSS before, set it up according to official docs.

Input this command in terminal and download this PostCSS plugin.

npm i postcss-rfs-autopilot

RFS is treated as an external dependency for this plugin, thus you would need to download and include it manually in your PostCSS config as usual.

npm i rfs

After you have installed this plugin, require it before RFS in your PostCSS configuration files, or the place where you config PostCSS in your environment

//postcss.config.js or other files you use to config PostCSS

module.exports = {
  plugins: [
    //Other plugins...
    //You have to include this plugin before rfs
    require('postcss-rfs-autopilot')(),
    require('rfs')()
  ]
}

Now we will mark up all the values for you with rfs()๐Ÿš€๐Ÿš€๐Ÿš€!

If you want to include or exclude some values or selectors, you can pass a configuration object to this plugin like this:

Check out our API Reference for configuration options.

//postcss.config.js or other files you use to config PostCSS

module.exports = {
  plugins: [
    //Other plugins...
    //You have to include this plugin before rfs
    require('postcss-rfs-autopilot')({
      includedRules: [
        '*'
      ], //Rules you want to include, e.g. font-size
      includedSelectors: [
        'p #hello'
      ], //Selectors you want to include,
      includedUnits: [
        'px', 'rem'
      ], //Units you want to include, e.g. px.  Noted that RFS currently only works with px and rem
      excludedRules: [], //Rules you want to exclude
      excludedSelectors: [], //Selectors you want to exclude
      excludedUnits: [] //Units you want to exclude
      }),
    require('rfs')
  ]
}

Examples

Apply rfs() to all values, selector, and rules except width and height:

module.exports = {
  plugins: [
    //Other plugins...
    require('postcss-rfs-autopilot')({
      excludedRules: ['width', 'height']
    }),
    require('rfs')
  ]
}

Apply rfs() to class foo and bar only:

module.exports = {
  plugins: [
    //Other plugins...
    require('postcss-rfs-autopilot')({
      includedSelectors: ['.foo', '.bar']
    }),
    require('rfs')
  ]
}

Advanced

Exclusion rules will have precedence over inclusion rules, which means that if a same rules is found in both includedRules and excludedRules, it will be excluded.

If you want to include all for an option, pass in "*" as its value.

API Reference

options.includedRules

Data type: [Array]

Default value: [ '*' ]

Description: Control which CSS rules you want this plugin wrap it up with rfs(), for example font-size

options.includedSelectors

Data type: [Array]

Default value: [ '*' ]

Description: Control which CSS selectors you want this plugin wrap it up with rfs(), for example p .free

options.includedUnits

Data type: [Array]

Default value: [ 'px', 'rem' ]

Description: Control which CSS units you want this plugin wrap it up with rfs(), for example px

options.excludedRules

Data type: [Array]

Default value: []

Description: Control which CSS rules you do not want this plugin wrap it up with rfs(), for example font-size

options.includedSelectors

Data type: [Array]

Default value: []

Description: Control which CSS selectors you do not want this plugin wrap it up with rfs(), for example p .free

options.includedUnits

Data type: [Array]

Default value: []

Description: Control which CSS units you do not want this plugin wrap it up with rfs(), for example px

options.silentConsole

Data type: [Boolean]

Default value: false

Description: Set it true to suppress all logs in console.

postcss-rfs-autopilot's People

Contributors

winston0410 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

postcss-rfs-autopilot's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.