按需加载echart中国地图,发现只要引入了china.js,按需加载无效,所有的内容都被引用进来
"webpack": "^3.6.0"
china.js 源码:
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports', 'echarts'], factory);
} else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
// CommonJS
factory(exports, require('echarts'));
} else {
// Browser globals
factory({}, root.echarts);
}
}(this, function (exports, echarts) {
echarts.registerMap()
})
修改后:
const echarts = require('echarts/lib/echarts')
echarts.registerMap()
无需手动修改配置
const echarts = require('echarts/lib/echarts')
require('echarts/lib/chart/line')
require('echarts/lib/chart/bar')
require('echarts/lib/chart/pictorialBar')
require('echarts/lib/chart/pie')
require('echarts/lib/chart/scatter')
require('echarts/lib/chart/effectScatter')
require('echarts/lib/chart/map')
require('echarts/lib/component/grid')
require('echarts/lib/component/tooltip')
require('echarts/lib/component/axisPointer')
require('echarts/lib/component/geo')
require('echarts/lib/component/visualMap')
require('echarts/lib/component/toolbox')
export default echarts
文档中也确实没有表明china.js可以按需加载:可以按需引入的模块列表
不知能否做增强
可以通过动态引入json类型的数据实现。
Most helpful comment
可以通过动态引入json类型的数据实现。