astro 调用组件前的逻辑判断并不能阻击打包组件内的客户端 JS

16次阅读

共计 533 个字符,预计需要花费 2 分钟才能阅读完成。

想着用选项控制在开启时引放评论

---
import Waline from "@/theme-simple/components/Waline.astro";
import {config} from "@/theme-simple/config";
---
{console.log(config.waline.enable)
}
{config.waline.enable && 
}

选项关闭时,html 不会被引入,但是 JS 仍然会打包进来执行。结果就是因为 html 元素不存在而报错。。对应的打包体积也会增加。。

---
import {config} from "@/theme-simple/config";
const configWaline = config.waline;
---

可以改成

Copyright Puock
 Theme by Puock