Skip to content

Commit b68bff6

Browse files
authored
Merge pull request #245 from NullVoxPopuli/add-tailwind-guide
Add tailwind appendix
2 parents a386f75 + 94a1d5c commit b68bff6

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

.local.dic

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ integrations
5757
Integrations
5858
Intellij-emberjs
5959
JetBrains
60+
JIT
6061
js-files
6162
linters
6263
LiveReload
@@ -105,4 +106,4 @@ VMware
105106
WebStorm
106107
Webstorm's
107108
workspaces
108-
WSL
109+
WSL

guides/appendix/live-reload.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
For most JavaScript dependencies, installing them in your Ember app can be as quick as `npm install <some package name>`.
2+
However, there are some libraries within the JavaScript ecosystem that have additional tooling that needs to integrate
3+
with Ember's live-reload features for the best developer-experience. In this guide, you will learn how to install
4+
and configure libraries to integrate with Ember's live-reload.
5+
6+
In short, any tool that can output or change files automatically can be used to add live-reload behavior.
7+
8+
The process is:
9+
10+
- emit some file to either the `public` or `app` tree
11+
- `link` or `import` the file from existing `ember` code
12+
13+
14+
## Tailwind
15+
16+
An example of this behavior and integration can be shown with a CSS authoring tool, Tailwind.
17+
18+
19+
[Tailwind](https://tailwindcss.com/) is a popular way to use utility-first CSS classes in an app. It can be used within many frontend frameworks, including Ember.
20+
21+
To use Tailwind JIT with Ember, this guide follows the [Tailwind Getting Started](https://tailwindcss.com/docs/installation) guide, with some minor tweaks to file names and their locations.
22+
23+
To get started, install the following dependencies:
24+
```shell
25+
npm install autoprefixer postcss tailwindcss
26+
```
27+
28+
Then, from your project's root directory, add the following files:
29+
30+
- `tailwind.config.js`
31+
32+
```js {data-filename="tailwind.config.js"}
33+
'use strict';
34+
35+
module.exports = {
36+
content: [`./app/**/*.{html,js,ts,hbs}`],
37+
theme: {
38+
extend: { },
39+
},
40+
plugins: [],
41+
};
42+
```
43+
44+
- `postcss.config.js`
45+
46+
```js {data-filename="postcss.config.js"}
47+
'use strict';
48+
49+
module.exports = {
50+
plugins: {
51+
tailwindcss: {},
52+
autoprefixer: {},
53+
}
54+
}
55+
```
56+
57+
- `tailwind-input.css`
58+
59+
```css {data-filename="tailwind-input.css"}
60+
@tailwind base;
61+
@tailwind components;
62+
@tailwind utilities;
63+
```
64+
65+
Now we need to add some scripts to the `package.json` to make
66+
interacting with the tailwind CLI a little easier.
67+
68+
```diff {data-filename="package.json"}
69+
+ "tailwind:build": "npx tailwindcss -i ./tailwind-input.css -o ./public/assets/tailwind.css",
70+
+ "tailwind:watch": "npx tailwindcss -i ./tailwind-input.css -o ./public/assets/tailwind.css --watch",
71+
+ "build": "npm run tailwind:build && ember build --environment=production",
72+
- "build": "ember build --environment=production",
73+
```
74+
75+
In addition to the two new scripts, `tailwind:build` and `tailwind:watch`, the `build` script, which was preexisting for production builds, has been prefixed with a call to `tailwind:build` so that the tailwind assets are prepped for shipping to production (useful for C.I.)
76+
77+
The above scripts expect that an input file, `./tailwind-input.css` will exist, and the tailwind CLI will output the compiled styles at `public/assets/tailwind.css`. Since this tailwind.css output file is in the public folder, changes to it will cause the `ember s` command to rebuild.
78+
79+
A couple notes though:
80+
- `npm run tailwind:watch` must be run in a separate terminal for development
81+
- it may be beneficial to add `public/assets/tailwind.css` to the `.gitignore`
82+
83+
Lastly, we need to edit the `app/index.html` file to include the `tailwind.css` file:
84+
85+
```html
86+
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/tailwind.css">
87+
```
88+
89+
With these things in place, you'll be able to use all of Tailwind's capabilities, including JIT compilation.

guides/pages.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,5 @@
8181
url: 'dev-tools'
8282
- title: 'Common issues'
8383
url: 'common-issues'
84+
- title: 'Live reload integration'
85+
url: 'live-reload'

0 commit comments

Comments
 (0)