If your project is a static site, like a simple webpage, you can't designate which files will cause your app to restart. However, you can toggle off the Refresh App on Changes option to prevent the project editor from automatically updating the app whenever changes are made.
- You can find this option in the project editor by clicking the little down arrow to the right of the project name. This will open the project options menu.
- In the project options menu, scroll down until you see the Refresh App on Changes option and give it a click to toggle off.
If your project is a full-stack or generated static site, you can add a file called watch.json
to your app, and the settings it contains will override the default install and restart trigger files and timings.
In a watch.json you can specify:
- Which files trigger a container install or restart when edited.
- The delay-time between making edits and those changes being applied.
Here is an example of code that might appear in a watch.json :
{
"install": {
"include": [
"^package\\.json$",
"^\\.env$"
]
},
"restart": {
"exclude": [
"^public/",
"^dist/"
],
"include": [
"\\.js$",
"\\.coffee$",
"\\.json"
]
},
"throttle": 100
}
Click here to see an example of a project that disables auto-restart entirely.
Configuring a watch.json
There are three top-level keys that you can use to configure a watch.json:
- restart
- install
- throttle
restart determines which files will cause Glitch to terminate the server and re-run the start command. You can select which files will trigger a restart by choosing which files to explicitly include or exclude. Both include and exclude are an array of regular expression patterns that match file paths in the project's code
- "^package\\.json$" selects a package.json file at the root of the project
- "\\.js$" will match any file ending in .js in the project
- ^dist/ is a folder called dist in the root of the project
install determines which files will cause Glitch to terminate the server, run the install command, and run start again. install takes the same include and exclude arrays as restart.
throttle lets you change how long the watcher waits to restart after it sees a change.
- The value is the number of milliseconds to wait after a change to restart
For more information, check out the Glitch project: watch-json.