我正在学习 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禁用 both HMR and any type of reloading . 对于您问题中的简单 HTML,只需删除 --no-hmr
标志即可。
但是,通过JS修改的更复杂的HTML可能会出现意想不到的副作用。有一个 pull request to add a --reload
flag , 但从未合并。您可以尝试根据 PR 修改自己的包裹,或者尝试使用 implement 的 fork 之一普通 reload .
关于parceljs - 包裹实时重新加载不适用于简单的 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54331785/