包裹实时重新加载不适用于简单 html
Parcel live reload does not works for simple html
我在学习parcel js。在文档中,描述了实时重新加载。
我怀疑当我更改 HTML 文件的内容时,我会看到我的网站正在重新加载并且项目将被重建。
如何重现错误?
我输入了两个 bash 脚本:
prepare.sh
#!/usr/bin/env bash
HTML="<html><body>1</body></html>";
echo ${HTML} > index.html;
它创建最简单的 HTML 文件。
1) 运行 这个脚本 bash prepare.sh
.
2) 现在在第二个航站楼 运行 parcel.
parcel index.html --no-cache --no-hmr --log-level 5
然后创建一个脚本来做主要测试:
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
所以。我再次创建 HTML 文件(替换它),我可以看到调用了构建过程。但是当我只修改 body 标签内的文件更改字符串时,什么也没有发生。包裹服务器没有检测到它。
--no-hmr
flag disables both HMR and any type of reloading. 对于您问题中的简单 HTML,只需删除 --no-hmr
标志即可。
但是,在通过JS修改的更复杂的HTML中,可能会出现意想不到的side-effects。有一个 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.
我在学习parcel js。在文档中,描述了实时重新加载。
我怀疑当我更改 HTML 文件的内容时,我会看到我的网站正在重新加载并且项目将被重建。
如何重现错误?
我输入了两个 bash 脚本:
prepare.sh
#!/usr/bin/env bash
HTML="<html><body>1</body></html>";
echo ${HTML} > index.html;
它创建最简单的 HTML 文件。
1) 运行 这个脚本 bash prepare.sh
.
2) 现在在第二个航站楼 运行 parcel.
parcel index.html --no-cache --no-hmr --log-level 5
然后创建一个脚本来做主要测试:
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
所以。我再次创建 HTML 文件(替换它),我可以看到调用了构建过程。但是当我只修改 body 标签内的文件更改字符串时,什么也没有发生。包裹服务器没有检测到它。
--no-hmr
flag disables both HMR and any type of reloading. 对于您问题中的简单 HTML,只需删除 --no-hmr
标志即可。
但是,在通过JS修改的更复杂的HTML中,可能会出现意想不到的side-effects。有一个 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.