Skip to content

Commit b80b355

Browse files
committed
Update CLI documentation
1 parent b78e282 commit b80b355

File tree

1 file changed

+56
-11
lines changed

1 file changed

+56
-11
lines changed

src/pages/docs/installation.mdx

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ For most real-world projects, we recommend installing Tailwind as a PostCSS plug
2828

2929
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.
3030

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.
3232

3333
### Install Tailwind via npm
3434

@@ -155,16 +155,16 @@ In this case, you should [switch to our PostCSS 7 compatibility build](#post-css
155155

156156
---
157157

158-
## Using Tailwind without PostCSS
158+
## Using Tailwind CLI
159159

160160
*Tailwind CSS requires Node.js 12.13.0 or higher.*
161161

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.
163163

164164
Use `npx` which is a tool that is automatically installed alongside `npm` to generate a fully compiled Tailwind CSS file:
165165

166166
```shell
167-
npx tailwindcss-cli@latest build -o tailwind.css
167+
npx tailwindcss -o tailwind.css
168168
```
169169

170170
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:
186186
</html>
187187
```
188188

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+
189197
### Using a custom CSS file
190198

191199
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
202210
@tailwind utilities;
203211
```
204212

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:
206214

207215
```shell
208-
npx tailwindcss-cli@latest build ./src/tailwind.css -o ./dist/tailwind.css
216+
npx tailwindcss -i ./src/tailwind.css -o ./dist/tailwind.css
209217
```
210218

211219
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
216224
If you'd like to customize what Tailwind generates, create a `tailwind.config.js` file using the Tailwind CLI tool:
217225

218226
```shell
219-
npx tailwindcss-cli@latest init
227+
npx tailwindcss init
220228
```
221229

222230
This will create a minimal `tailwind.config.js` file at the root of your project:
@@ -237,13 +245,13 @@ module.exports = {
237245
This file will automatically be read when building your CSS with `npx tailwindcss build`:
238246

239247
```shell
240-
npx tailwindcss-cli@latest build ./src/tailwind.css -o ./dist/tailwind.css
248+
npx tailwindcss -i ./src/tailwind.css -o ./dist/tailwind.css
241249
```
242250

243251
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:
244252

245253
```shell
246-
npx tailwindcss-cli@latest build ./src/tailwind.css -c ./.config/tailwind.config.js -o ./dist/tailwind.css
254+
npx tailwindcss -i ./src/tailwind.css -c ./.config/tailwind.config.js -o ./dist/tailwind.css
247255
```
248256

249257
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
253261
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:
254262

255263
```shell
256-
npx tailwindcss-cli@latest build --no-autoprefixer -o tailwind.css
264+
npx tailwindcss --no-autoprefixer -o tailwind.css
265+
```
266+
267+
### Using a custom PostCSS configuration
268+
269+
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
257297
```
258298

259299
### Building for production
260300

261301
When building for production, set `NODE_ENV=production` on the command line when building your CSS:
262302

263303
```shell
264-
NODE_ENV=production npx tailwindcss-cli@latest build ./src/tailwind.css -o ./dist/tailwind.css
304+
NODE_ENV=production npx tailwindcss -i ./src/tailwind.css -o ./dist/tailwind.css
265305
```
266306

267307
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.
268308

309+
You can also use the `--minify` flag to compress your CSS with [cssnano](https://cssnano.co/):
310+
311+
```shell
312+
NODE_ENV=production npx tailwindcss -i ./src/tailwind.css -o ./dist/tailwind.css --minify
313+
```
269314

270315
---
271316

0 commit comments

Comments
 (0)