50_adding_css.md 1.61 KB
Newer Older
Sebastian Wilzbach's avatar
Sebastian Wilzbach committed
1
2
3
4
---
title: 'Adding CSS'
layout: series_item
series: 'details'
5
permalink: details/css/
Sebastian Wilzbach's avatar
Sebastian Wilzbach committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
estimated-time: 10
---

{% hlblock info %}
We use [`parcelify`](https://github.com/rotundasoftware/parcelify) as this allows a CSS dependency chain (as you no it from browserify).
{% endhlblock %}

### 1. Add your CSS files to the `style` field

`package.json`

~~~
 "style" : "css/*.css"
~~~

21
or
Sebastian Wilzbach's avatar
Sebastian Wilzbach committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

~~~
 "style" : "*.scss"
~~~

{% hlblock info %}
The registry now _only_ picks the `style` dependencies - it doesn't merge it with your css files in the sniper section. So be sure that you add all css files - the "style" attribute can also be an array.
{% endhlblock %}

{% alert warn %}
You need to install `npm` before you can start to rock. See <a href="20_getting_started.html"> the getting started guide </a> for more info.
{% endalert %}

### 2. Adding a build tasks and updating the sniper

2.1) Install parcelify

~~~
npm install parcelify --save-dev
~~~

2.2) Adding it as a build task

`package.json`

~~~
"scripts": {
...
 "css": "parcelify ./ -c build/bundle.css",
...
}
~~~

2.3) Update the sniper

~~~
css: ["/build/bundle.css"]
~~~

2.4) Optional: Parcelify has a watch mode

~~~
parcelify ./ -w -c build/bundle.css
~~~

### 3. Using a preprocessor (SASS, LESS, ...)

For CSS preprocessors like SASS or LESS you can use a parcelify tranform, see this example for SASS:

~~~
  "transforms" : [ "sass-css-stream" ],
  "dependencies" : {
    "sass-css-stream": "~0.0.1"
  }
~~~

{% hlblock info %}
Do you want to [learn more](https://github.com/rotundasoftware/parcelify#local-package-specific-transforms) about parcelify transforms?
{% endhlblock %}