How to hot-reload Hugo within Dev Containers in Windows
Table of Contents
TL;DR #
Run Hugo’s CLI serve
command with the poll
flag and the interval of
milliseconds you want your files to be checked for changes:
hugo serve --poll 700
You can add this to your tasks.json
in .vscode
directory:
|
|
A small research on this issue #
If you ever happened to work with Hugo and Visual Studio Code’s Dev Containers in Windows (and not inside WSL2) then you probably noticed that the hot-reload feature of watching changes didn’t work at all.
This issue is, apparently, due to Windows’ app working code hosted in
Windows’ filesystem are unable to trigger notifications to
WSL/WSL2’s apps. And this, of course, includes file changes done in vscode.
Windows’ filesystem is, mostly, mounted following 9P protocol
which is currently incompatible with a piece of linux software called inotify
when using Windows formatted hard drives and WSL2.
As a workaround, although inefficient, we can use a polling approach to check for changes in an interval of time instead of depending on the (sub)system’s triggers.