webpack打包后js代码失效,函数功能出现not defined,请问应该怎么解决?-灵析社区

CO_co

因为生成的`index.html`中,引入 `js` 添加了 `defer`。 ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241014/631573ca35ea5dcbb52a2ded7312182d.png) `ck` 在 `onload` 中调用,js 已经执行,所以有效 ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241014/c248a324a737f076215532d1cc56b721.png) `lib` 调用时,js 还未执行,所以无效 ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241014/223ca76dc6093dfd62fca16be22c055b.png) ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241014/32210745cc4194ee19ac984858b1d94f.png) > 这个布尔属性的设置是为了向浏览器表明,该脚本是要在文档被解析后,但在触发 DOMContentLoaded 事件之前执行的。 > [https://developer.mozilla.org/zh-> CN/docs/Web/HTML/Element/scr...](https://link.segmentfault.com/?enc=MKm6I52m%2BuPPbEpfwT39Gg%3D%3D.biyYryedzbFiBLs1lcpclKHMiQwbI4OyXpWMqpS20%2BETL1WQW6gkV%2Bv1sxiTwGW32xAkI3AZ0hZAKrA1hjeET%2FsegRfxt4fOq3mQY29oHxc%3D)

阅读量:1

点赞量:0

问AI