postcss-rfs-autopilot
v1.1.3
Published
A PostCSS plugin that will automagically mark your CSS up with rfs() for RFS
Downloads
10
Maintainers
Readme
PostCSS RFS Autopilot
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 :free: :free:
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()
:rocket::rocket::rocket:!
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.