2017-10-23 18:25:16 +00:00
[![Deploy to now ](https://deploy.now.sh/static/button.svg )](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-global-stylesheet-simple)
2018-04-03 12:19:05 +00:00
# Global Stylesheet Example (Simple Version - CSS inside `node_modules`)
## How to use
### Using `create-next-app`
Execute [`create-next-app` ](https://github.com/segmentio/create-next-app ) with [Yarn ](https://yarnpkg.com/lang/en/docs/cli/create/ ) or [npx ](https://github.com/zkat/npx#readme ) to bootstrap the example:
```bash
npx create-next-app --example with-global-stylesheet-simple with-global-stylesheet-simple-app
# or
yarn create next-app --example with-global-stylesheet-simple with-global-stylesheet-simple-app
```
### Download manually
Download the example [or clone the repo ](https://github.com/zeit/next.js ):
```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-global-stylesheet-simple
cd with-global-stylesheet-simple
```
Install it and run:
```bash
npm install
npm run dev
# or
yarn
yarn dev
```
Deploy it to the cloud with [now ](https://zeit.co/now ) ([download](https://zeit.co/download))
```bash
now
```
## The idea behind the example
2017-10-23 18:25:16 +00:00
This is an example of importing a CSS file located inside `node_modules` (ones you downloaded using `npm` or `yarn` ).
This would be useful for importing CSS libraries such as [`normalize.css` ](https://necolas.github.io/normalize.css/ ).
### What if I want to import my own CSS, such as `styles/foo.css`?
Check out the [with-global-stylesheet ](../with-global-stylesheet ) example.
### How It Works
2018-04-03 12:19:05 +00:00
* Install `babel-plugin-inline-import` using `npm` or `yarn`
* Then, add this to your `.babelrc` :
2017-10-23 18:25:16 +00:00
```js
{
"plugins": [
[
"inline-import",
{
"extensions": [".css"]
}
]
],
"presets": ["next/babel"],
"ignore": []
}
```
2018-05-13 16:08:44 +00:00
* Install any CSS library using `npm` or `yarn` . In this example, I installed [`tachyons` ](https://tachyons.io/ ).
2018-04-03 12:19:05 +00:00
* Import the CSS file. Here, I'm importing a CSS file located at `node_modules/tachyons/css/tachyons.min.css` .
2017-10-23 18:25:16 +00:00
```js
2018-04-03 12:19:05 +00:00
import tachyons from "tachyons/css/tachyons.min.css";
2017-10-23 18:25:16 +00:00
```
2018-04-03 12:19:05 +00:00
* Add it globally using `styled-jsx` :
2017-10-23 18:25:16 +00:00
```js
2018-04-03 12:19:05 +00:00
< style jsx global >
{tachyons}
< / style >
2017-10-23 18:25:16 +00:00
```
### Result ([`index.js`](pages/index.js)):
![](example.png)