You are using an unsupported browser. Please update your browser to the latest version on or before July 31, 2020.
close
Home > Project Editor > Can I change which files cause my app to restart?
Can I change which files cause my app to restart?
print icon

Yes, 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:

  1. restart
  2. install
  3. 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.

Got more questions? Check out our Community Forum!
Open 24/7, the forum is where Glitch makers help each other and show off all the rad apps that they have created. It's the friendliest community of coders on the Web!
Feedback
2 out of 4 found this helpful

scroll to top icon