2017-11-07 14:39:07 +11:00
|
|
|
---
|
|
|
|
|
id: watching-files
|
|
|
|
|
title: Watching For Changes
|
|
|
|
|
---
|
|
|
|
|
|
2020-06-28 03:47:29 +02:00
|
|
|
You can have Prettier watch for changes from the command line by using [onchange](https://www.npmjs.com/package/onchange). For example:
|
2017-11-07 14:39:07 +11:00
|
|
|
|
2020-04-03 18:44:03 +08:00
|
|
|
```bash
|
2020-08-21 09:11:59 +08:00
|
|
|
npx onchange "**/*" -- npx prettier --write --ignore-unknown {{changed}}
|
2017-11-07 14:39:07 +11:00
|
|
|
```
|
|
|
|
|
|
2020-06-28 03:47:29 +02:00
|
|
|
Or add the following to your `package.json`:
|
2017-11-07 14:39:07 +11:00
|
|
|
|
|
|
|
|
```json
|
2020-04-03 18:44:03 +08:00
|
|
|
{
|
2017-11-07 14:39:07 +11:00
|
|
|
"scripts": {
|
2020-08-21 09:11:59 +08:00
|
|
|
"prettier-watch": "onchange \"**/*\" -- prettier --write --ignore-unknown {{changed}}"
|
2020-04-03 18:44:03 +08:00
|
|
|
}
|
|
|
|
|
}
|
2017-11-07 14:39:07 +11:00
|
|
|
```
|