2014-05-27 18:32:57 -04:00
|
|
|
|
---
|
2016-08-09 19:14:40 -04:00
|
|
|
|
lastmod: 2016-08-09
|
2014-05-29 18:42:05 -04:00
|
|
|
|
date: 2014-05-26
|
2014-05-27 18:32:57 -04:00
|
|
|
|
menu:
|
|
|
|
|
main:
|
2014-05-29 18:42:05 -04:00
|
|
|
|
parent: extras
|
|
|
|
|
next: /extras/menus
|
2016-12-11 19:55:36 -05:00
|
|
|
|
prev: /extras/gitinfo
|
2015-01-09 13:51:15 -05:00
|
|
|
|
title: LiveReload
|
2014-05-27 18:32:57 -04:00
|
|
|
|
---
|
|
|
|
|
|
2015-01-09 13:51:15 -05:00
|
|
|
|
Hugo may not be the first static site generator to utilize LiveReload
|
2014-05-27 18:32:57 -04:00
|
|
|
|
technology, but it’s the first to do it right.
|
|
|
|
|
|
2015-01-09 13:51:15 -05:00
|
|
|
|
The combination of Hugo’s insane build speed and LiveReload make
|
2014-05-27 18:32:57 -04:00
|
|
|
|
crafting your content pure joy. Virtually instantly after you hit save
|
|
|
|
|
your rebuilt content will appear in your browser.
|
|
|
|
|
|
2015-01-09 13:51:15 -05:00
|
|
|
|
## Using LiveReload
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2015-01-09 13:51:15 -05:00
|
|
|
|
Hugo comes with LiveReload built in. There are no additional packages to
|
|
|
|
|
install. A common way to use Hugo while developing a site is to have
|
|
|
|
|
Hugo run a server and watch for changes:
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2016-08-09 19:14:40 -04:00
|
|
|
|
{{< nohighlight >}}$ hugo server
|
|
|
|
|
{{< /nohighlight >}}
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
|
|
|
|
This will run a full functioning web server while simultaneously
|
|
|
|
|
watching your file system for additions, deletions or changes within
|
|
|
|
|
your:
|
|
|
|
|
|
|
|
|
|
* static files
|
|
|
|
|
* content
|
2015-04-01 17:25:18 -04:00
|
|
|
|
* data files
|
2014-05-27 18:32:57 -04:00
|
|
|
|
* layouts
|
|
|
|
|
* current theme
|
2016-08-09 19:14:40 -04:00
|
|
|
|
* configuration files
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2016-08-09 19:14:40 -04:00
|
|
|
|
Whenever anything changes, Hugo will rebuild the site while continuing to serve
|
|
|
|
|
the content. As soon as the build is finished, it will tell the
|
|
|
|
|
browser and silently reload the page. Because most Hugo builds are so
|
2014-05-27 18:32:57 -04:00
|
|
|
|
fast they are barely noticeable, you merely need to glance at your open
|
2016-08-09 19:14:40 -04:00
|
|
|
|
browser and you will see the change, already there.
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
|
|
|
|
This means that keeping the site open on a second monitor (or another
|
2015-01-09 13:51:15 -05:00
|
|
|
|
half of your current monitor) allows you to see exactly what your
|
2016-08-09 19:14:40 -04:00
|
|
|
|
content looks like, without even leaving your text editor.
|
|
|
|
|
|
|
|
|
|
## Disabling Watch
|
|
|
|
|
|
|
|
|
|
If for some reason you don't want the Hugo server's watch functionality,
|
|
|
|
|
just do:
|
|
|
|
|
|
|
|
|
|
{{< nohighlight >}}$ hugo server --watch=false
|
|
|
|
|
{{< /nohighlight >}}
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2015-01-09 13:51:15 -05:00
|
|
|
|
## Disabling LiveReload
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2016-08-09 19:14:40 -04:00
|
|
|
|
LiveReload works by injecting JavaScript into the pages Hugo generates,
|
|
|
|
|
which creates a connection from the browser web socket client to the
|
|
|
|
|
Hugo web socket server.
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
|
|
|
|
Awesome for development, but not something you would want to do in
|
2016-08-09 19:14:40 -04:00
|
|
|
|
production. Since many people use `hugo server` in production to
|
2014-05-27 18:32:57 -04:00
|
|
|
|
instantly display any updated content, we’ve made it easy to disable the
|
2016-08-09 19:14:40 -04:00
|
|
|
|
LiveReload functionality:
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2016-08-09 19:14:40 -04:00
|
|
|
|
{{< nohighlight >}}$ hugo server --disableLiveReload
|
|
|
|
|
{{< /nohighlight >}}
|
2014-05-27 18:32:57 -04:00
|
|
|
|
|
2016-05-25 15:20:22 -04:00
|
|
|
|
## Notes
|
|
|
|
|
|
|
|
|
|
You must have a closing `</body>` tag for LiveReload to work.
|
|
|
|
|
Hugo injects the LiveReload `<script>` before this tag.
|