Skip to main content

How to hot-reload Hugo within Dev Containers in Windows

··2 mins

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Serve",
            "type": "shell",
            "command": "hugo server -D --poll 700",
            "group": {
                "kind": "test",
                "isDefault": true
            },
            "isBackground": true,
            "problemMatcher": []
        },
        {
            "label": "Build",
            "type": "shell",
            "command": "hugo",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": []
        }
    ]
}

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.

Alexis Flores
Author
Alexis Flores
I’m a multidisciplinary engineer with more than 5 years of experience working on data-driven solutions for multinational institutions in the financial services and in-house solutions."