Daniel
Daniel

Reputation: 8657

Parcel live reload does not works for simple html

I learning parcel js. In the documentation, there is described live reload.

https://parceljs.org/getting_started.html

I suspect that when I will change the content of HTML file I will see that my website is reloading and a project will be rebuilt.


How to reproduce the bug?

I typed two bash scripts:

prepare.sh

#!/usr/bin/env bash

HTML="<html><body>1</body></html>";

echo ${HTML} > index.html;

It creates the simplest possible HTML file.

1) Run this script bash prepare.sh.

2) Now in the second terminal run parcel.

parcel index.html --no-cache --no-hmr --log-level 5

Then create a script to do the main test:

test.sh

#!/usr/bin/env bash

HTML="<html><body>1</body></html>";

echo ${HTML} > index.html;


# I checking if html served by parcel contains 1, it should and conatin
if [[ $(curl -s localhost:1234 | grep 1 | wc -l) -eq 1 ]]; then
    echo "GREAT when the index is replaced project is rebuilt";
else
    echo "WRONG";
fi

# I replacing 1 inside of a body tag to 12 
perl -pi -e 's/1/12/g' index.html

echo "waiting 1 second for the rebuild...";
sleep 1;

# I checking if html served by parcel contains 2, it should but not conatin 
if [[ $(curl -s localhost:1234 | grep 2 | wc -l) -eq 1 ]]; then
    echo "GREAT";
else
    echo "WRONG but when I only modified file project parcel did not see it";
fi

So. I creating HTML file again (replacing it) and I can see that building process is invoked. But when I only modifying file changing string inside of body tag, then nothing happens. Parcel server did not detect it.

Upvotes: 3

Views: 3358

Answers (1)

Leftium
Leftium

Reputation: 17903

The --no-hmr flag disables both HMR and any type of reloading. For the simple HTML in your question, simply removing the --no-hmr flag should work.

However, unexpected side-effects may occur in more complex HTML that is modified via JS. There was a pull request to add a --reload flag, but it was never merged. You can try to modify your own parcel based on the PR, or try one of the forks that implement plain reload.

Upvotes: 2

Related Questions