Import modules on demand

0

I'm using a lib in my project and I load the components I use through the commonjs module system. The code looks like this:

let echart = require('echarts/lib/echarts');
require('echarts/lib/chart/scatter');
require('echarts/lib/component/title');
require('echarts/lib/component/toolbox');
require('echarts/lib/component/tooltip');
require('echarts/lib/component/legendScroll');

In this way, the bundle generated by the webpack is 1.17 MB.

However, I decided to migrate the project to typescript and load the components of lib through the import of es6. The code looks like this:

import * as echarts from 'echarts';
import ECharts = echarts.ECharts;
import EChartOption = echarts.EChartOption;

In this way the bundle package for the webpack is 2.21 MB. Because all components are imported, even those that I do not use.

Because of this inconvenience, I would like to be able to import components on demand as well as commonjs into the es6 modules system. Do you know if it is possible and how to do it?

    
asked by anonymous 24.02.2018 / 19:10

0 answers