Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use normalize.css with npm?

Tags:

css

npm

I'm handling my dependencies with npm, but until now I used it mainly for Javascript code and I always imported the installed packages in my code with the useful require().

Recently I found that normalize.css could be installed with npm.
What are the advantages? How do I use it in my code (both static .html and dynamic .js files) after installation?

like image 518
seldon Avatar asked Oct 14 '14 16:10

seldon


People also ask

How do you normalize CSS?

There are two ways to use Normalize in a project: edit the source to customize your own Normalize stylesheet, or use it as a base and add styles on top. The former is a pick-and-choose strategy where you go through the Normalize. css file and delete whatever you don't need to make your own custom stylesheet.

How do you install normalize CSS in react?

To start using it, add @import-normalize; anywhere in your CSS file(s). You only need to include it once and duplicate imports are automatically removed. Since you only need to include it once, a good place to add it is index. css or App.

Should I use normalize CSS?

Browsers apply styles to elements before you've written any CSS at all, and sometimes those styles vary. Normalizing your CSS lets you rest assured, knowing that you have the same base layer of styles applied across all browsers.


1 Answers

parcelify is really useful for doing just this. You can use it in concert with the normalize.css package.

JS:

require('normalize.css');

then run parcelify:

$ parcelify main.js -c bundle.css

You can add an npm script to your package.json so you don't have to install parcelify globally to use it in your project:

package.json:

{
  "name": "your-package",
  "version": "0.0.0",
  "description": "Your package",
  "main": "main.js",
  "scripts": {
    "build": "parcelify main.js -c bundle.css"
  }
}

and then just do:

$ npm run build
like image 69
zakangelle Avatar answered Sep 21 '22 11:09

zakangelle