You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/docs/installation.mdx
+56-11Lines changed: 56 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ For most real-world projects, we recommend installing Tailwind as a PostCSS plug
28
28
29
29
If you've never heard of PostCSS or are wondering how it's different from tools like Sass, read our guide on [using PostCSS as your preprocessor](/docs/using-with-preprocessors#using-post-css-as-your-preprocessor) for an introduction.
30
30
31
-
If this is a bit over your head and you'd like to try Tailwind without configuring PostCSS, read our instructions on [using Tailwind without PostCSS](#using-tailwind-without-post-css) instead.
31
+
If this is a bit over your head and you'd like to try Tailwind without configuring PostCSS, read our instructions on [using Tailwind CLI](#using-tailwind-cli) instead.
32
32
33
33
### Install Tailwind via npm
34
34
@@ -155,16 +155,16 @@ In this case, you should [switch to our PostCSS 7 compatibility build](#post-css
155
155
156
156
---
157
157
158
-
## Using Tailwind without PostCSS
158
+
## Using Tailwind CLI
159
159
160
160
*Tailwind CSS requires Node.js 12.13.0 or higher.*
161
161
162
-
For simple projects or just giving Tailwind a spin, you can use the Tailwind CLI tool to generate your CSS without configuring PostCSS or even installing Tailwind as a dependency if you don't want to.
162
+
If you'd like to compile your CSS with Tailwind without integrating it directly into any sort of build tooling, you can use the Tailwind CLI tool to generate your CSS without configuring PostCSS or even installing Tailwind as a dependency if you don't want to.
163
163
164
164
Use `npx` which is a tool that is automatically installed alongside `npm` to generate a fully compiled Tailwind CSS file:
165
165
166
166
```shell
167
-
npx tailwindcss-cli@latest build -o tailwind.css
167
+
npx tailwindcss -o tailwind.css
168
168
```
169
169
170
170
This will create a file called `tailwind.css` generated based on Tailwind's [default configuration](https://unpkg.com/browse/tailwindcss@^2/stubs/defaultConfig.stub.js), and automatically add any necessary vendor prefixes using [autoprefixer](https://github.com/postcss/autoprefixer).
@@ -186,6 +186,14 @@ Now you can pull this file into your HTML just like any other stylesheet:
186
186
</html>
187
187
```
188
188
189
+
### Watching for changes
190
+
191
+
You can use the `--watch` or `-w` flag to start a watch process and automatically rebuild your CSS any time you make any changes:
192
+
193
+
```shell
194
+
npx tailwindcss -o tailwind.css --watch
195
+
```
196
+
189
197
### Using a custom CSS file
190
198
191
199
If you'd like to process any custom CSS alongside the default styles Tailwind generates, create a CSS file wherever you normally would and use the `@tailwind` directive to include Tailwind's `base`, `components`, and `utilities` styles:
@@ -202,10 +210,10 @@ If you'd like to process any custom CSS alongside the default styles Tailwind ge
202
210
@tailwind utilities;
203
211
```
204
212
205
-
Then include the path to that file when building your CSS with `npx tailwindcss build`:
213
+
Then include the path to that file when building your CSS:
Read about [adding base styles](/docs/adding-base-styles), [extracting components](/docs/extracting-components), and [adding new utilities](/docs/adding-new-utilities) to learn more about adding custom CSS on top of Tailwind.
@@ -216,7 +224,7 @@ Read about [adding base styles](/docs/adding-base-styles), [extracting component
216
224
If you'd like to customize what Tailwind generates, create a `tailwind.config.js` file using the Tailwind CLI tool:
217
225
218
226
```shell
219
-
npx tailwindcss-cli@latest init
227
+
npx tailwindcss init
220
228
```
221
229
222
230
This will create a minimal `tailwind.config.js` file at the root of your project:
@@ -237,13 +245,13 @@ module.exports = {
237
245
This file will automatically be read when building your CSS with `npx tailwindcss build`:
If you'd like to keep your config file in a different location or give it a different name, pass the config file path using the `-c` option when building your CSS:
Learn more about configuring Tailwind in the [configuration documentation](/docs/configuration).
@@ -253,19 +261,56 @@ Learn more about configuring Tailwind in the [configuration documentation](/docs
253
261
By default, the Tailwind CLI tool will run your CSS through [Autoprefixer](https://github.com/postcss/autoprefixer) to add any necessary vendor prefixes. If you already have Autoprefixer set up in your build pipeline somewhere further down the chain, you can disable it in the Tailwind CLI tool using the `--no-autoprefixer` flag to avoid running it twice:
If you'd like to use other PostCSS plugins alongside Tailwind, you can create a `postcss.config.js` file to add your extra plugins and Tailwind will include them when building your CSS:
270
+
271
+
```js
272
+
// postcss.config.js
273
+
module.exports= {
274
+
plugins: [
275
+
require('postcss-100vh-fix'),
276
+
]
277
+
}
278
+
```
279
+
280
+
By default, plugins are run _after_ Tailwind. If you have plugins that need to run before Tailwind, just include `tailwindcss` in your plugin list and Tailwind CLI will detect it and respect your custom plugin order:
281
+
282
+
```js
283
+
// postcss.config.js
284
+
module.exports= {
285
+
plugins: [
286
+
require('postcss-import'),
287
+
require('tailwindcss'),
288
+
require('postcss-100vh-fix'),
289
+
]
290
+
}
291
+
```
292
+
293
+
If you'd like to automatically generate a basic `postcss.config.js` file when creating your `tailwind.config.js` file, use the `--postcss` or `-p` flag when initializing your config file:
294
+
295
+
```shell
296
+
npx tailwindcss init --postcss
257
297
```
258
298
259
299
### Building for production
260
300
261
301
When building for production, set `NODE_ENV=production` on the command line when building your CSS:
This will make sure Tailwind removes any unused CSS for best performance. Read our separate guide on [optimizing for production](/docs/optimizing-for-production) to learn more.
268
308
309
+
You can also use the `--minify` flag to compress your CSS with [cssnano](https://cssnano.co/):
0 commit comments