[FE] G2Plot 在 Vue 中使用 CDN 方式避免构建时增大 js 体积

通过llama.cpp与羊驼聊天的网页界面- 详解 Serge 的启动使用

 

使用 npm、yarn 方式安装的包,虽方便使用,但是会极大增加 vendor.xx.js 体积,拖慢网站运行速度。

以 G2Plot 为例,实际在 build 构建时,会下载一些额外字体到 vendor.xx.js 中。

 

要解决这个问题,选择引入 CDN 是比较常见的方式,在 Vue 中可以参考如下写法:

 

在 index.html header 中引入 g2plot.min.js,并加 G2Plot 挂到 window 上面。

<script src="https://xxxxx/g2plot.min.js"></script>
<script>window._G2Plot = G2Plot</script>

 之后在 .vue 文件中就可以使用 window._G2Plot.Line('xx') 这种方式了。

 

Refer:快速使用G2Plot

Link:https://www.cnblogs.com/farwish/p/12940820.html

posted on 2020-05-23 21:54  ercom  阅读(675)  评论(0编辑  收藏  举报