目录
官方解释是:
The externals configuration option provides a way of excluding dependencies from the output bundles. Instead, the created bundle relies on that dependency to be present in the consumer's environment.externals配置选项提供了「从输出的 bundle 中排除依赖」的方法。相反,所创建的 bundle 依赖于那些存在于用户环境(consumer's environment)中的依赖。用法
防止将某些
import的包打包到bundle中,而是在运行时(runtime)再去外部获取这些扩展依赖(external dependencies)
可以通过多种编写方式实现:string,array,object,function,regex。这里,我只说一些简单的内容,详细讲解,我觉得

- 第二种情况,通过
npm run build --report得出的报告,将一些不常修改的大包作为外部扩展。
这需要做两步操作:第一步修改webpack.base.conf.js文件,第二步,将外部扩展的内容通过其他方式加载到window环境,这里,我们通过<script>标签,并使用cdn来完成。
配置的文件:webpack.base.conf.js
externals: { vue : 'Vue', "echarts": 'echarts', "element-ui": 'ELEMENT' }在模板文件index.html中,添加<script>标签
<script src="upload/201811271639320262.png" alt="second build" style="margin: 0px; padding: 0px; border: 0px; max-width: 800px; height: auto;" />

这两种情况,我们主要从打包的时间,打包之后包的大小,实际浏览器中加载时长三个方面来做比较。
打包时间
打包时间,由原来的38s缩短至18s,大大减少了打包时间。
打包之后包的大小
主要看vendor包的大小,由原来的1.45M缩小至41.3k,缩小的内容,我们使用cdn,使其存在于外部环境。
由于
