Skip to content

使用webpack的externals来指定echarts无法减少包的大小 #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SidKwok opened this issue Jun 12, 2017 · 8 comments
Closed

使用webpack的externals来指定echarts无法减少包的大小 #92

SidKwok opened this issue Jun 12, 2017 · 8 comments

Comments

@SidKwok
Copy link

SidKwok commented Jun 12, 2017

重现步骤:

  1. 在vue-cli/webpack的webpack.base.conf.js中加入:
externals: {
  'echarts': 'window.echarts'
}
  1. 打包出来的vendor大小是 713kb

  2. 去掉externals打包出来的vendor大小是:713kb

还是把所有东西打包到bundle中去了,有解决方法吗?还是说我的使用方式有问题?

我是想通过script方式引入echarts来并行加载echarts的

@Justineo
Copy link
Member

vue-echarts 没有引入 echarts,引入的是 echarts/lib/echarts。我感觉是和这个有关。

@blusewang
Copy link

我也是,全写成require('echarts')也没用!
@SidKwok 楼主有解决么?
这货太TM大了!

SidKwok added a commit to SidKwok/vue-echarts that referenced this issue Aug 18, 2017
@SidKwok SidKwok mentioned this issue Aug 18, 2017
@Justineo
Copy link
Member

Justineo commented Nov 7, 2017

我理解不应该把 echarts 单独放到一个 <script> 加载然后通过全局变量引用呀,是否尝试过使用 webpack 自带的 code split 功能呢?

@Justineo
Copy link
Member

Justineo commented Nov 8, 2017

如果 code split 无效,再讨论这个 issue。先关闭了。

@Justineo Justineo closed this as completed Nov 8, 2017
@manooog
Copy link

manooog commented Jan 10, 2018

@Justineo 尝试过 使用commonsChunk无法剥离出echarts

@vkboo
Copy link

vkboo commented Jul 8, 2020

参考webpack官方文档,实际测试可用。
image

@wunai006
Copy link

不要用require,直接在main.js中import 然后vue.use就行。

  1. 在webpack.base.config.js中加入externals的echarts
  2. 在最外层的index.js加入cdn引入(就是<script src=""></script>)
  3. 在main.js照常引入echarts
    我这样打包下来就只有几k

@EMMMMMMMMMMMMM
Copy link

参考webpack官方文档,实际测试可用。
image

确实解决了问题, 棒棒!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants