Socket
Book a DemoInstallSign in
Socket

webpack-css-utils

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-css-utils

Webpack loader and plugin to generate and inject CSS utilities to your apps

latest
Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

webpack-css-utils

Build Status Code Coverage Package Version

Webpack plugin to generate and inject CSS utilities to your application.

How does it work?

All you have to do is specify utility classes on any DOM elements and webpack will generate and inject the CSS into your app.

For example, if you want to add bottom margin of 20px to a link, you can do that

<a href="/" class="logo mb20">I have bottom margin</a>
<p>Here is some text having some <span class="fw600">important bold information</span> in it.</p>

Currently supported formuals are listed below.

FormulaCSS PropertyExample Usage
ppaddingp10 will translate to padding: 10px
ptpadding-toppt20 will translate to padding-top: 20px;
pbpadding-bottompb10 will translate to padding-bottom: 10px;
prpadding-rightpr20 will translate to padding-right: 20px;
plpadding-leftpl23 will translate to padding-left: 23px;
mmarginm20 will translate to margin: 20px
mtmargin-topmt20 will translate to margin-top: 20px;
mbmargin-bottommb20 will translate to margin-bottom: 20px;
mlmargin-leftml50 will translate to margin-left: 50px;
mrmargin-rightmr30 will translate to margin-right: 30px;
wwidthw200 will translate to width: 200px
hheighth60 will translate to height: 60px;
brborder-radiusbr5 will translate to border-radius: 5px;
fsfont-sizefs15 will translate to font-size: 15px
fwfont-weightfw400 will translate to font-weight: 400px
lhline-heightlh20em will translate to line-height: 20em
ttopt6 will translate to top: 6px;
lleftl30 will translate to left: 30px
bbottomb20em will translate to bottom: 20em;
rrightr20em will translate to right: 20em;

How to use?

Install the plugin using npm or yarn

npm install webpack-css-utils --save-dev
yarn add webpack-css-utils --dev

Add the loader to module.rules in your webpack configuration

const CssUtils = require('webpack-css-utils');

// ...
module: {
  // Add the loader in the loader's list
  // it can handle HTML as well as JSX files
  rules: [
    // ...
    {
      test: /\.js$/,
      exclude: /node_modules/,
      use: CssUtils.Loader
    }
  ]
},
// ...
plugins: [
  // Add the plugin right after html-webpack-plugin
  // new HtmlWebpackPlugin(..),  // <-- You must have it installed and set up
  new CssUtils.Plugin(),
]
// ...

Notes for Units

All the default CSS units are supported. You can specify it and relevant CSS unit will be used

  • Units including px, pt, em, p, vh, vw, vmin, ex, cm, in, mm, pc will translate to the same unit in CSS
  • If you don't provide any unit px will be used
  • If you need % specify it as p e.g. w50p will get translated to width: 50%
  • If no unit is needed, specify n e.g. fw600n will translate to font-weight: 600

License

MIT © Kamran Ahmed

Keywords

webpack

FAQs

Package last updated on 17 Aug 2018

Did you know?

Socket

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.

Install

Related posts