function buildMinimalBundleCode()

in common/buildCode.js [218:305]


function buildMinimalBundleCode(deps, includeType) {
  const chartsImports = [];
  const componentsImports = [];
  const chartsGLImports = [];
  const componentsGLImports = [];
  const featuresImports = [];
  const renderersImports = [];
  const extensionImports = [];
  deps.forEach(function (dep) {
    if (dep.endsWith('Renderer')) {
      renderersImports.push(dep);
    } else if (CHARTS_MAP_REVERSE[dep]) {
      chartsImports.push(dep);
      if (includeType) {
        chartsImports.push(dep.replace(/Chart$/, 'SeriesOption'));
      }
    } else if (COMPONENTS_MAP_REVERSE[dep]) {
      componentsImports.push(dep);
      if (includeType) {
        componentsImports.push(dep.replace(/Component$/, 'ComponentOption'));
      }
    } else if (dep === 'TransformComponent') {
      // TransformComponent don't have individual option type.
      // TODO will put in to an config if there are other similar components
      componentsImports.push(dep);
    } else if (CHARTS_GL_MAP_REVERSE[dep]) {
      chartsGLImports.push(dep);
    } else if (COMPONENTS_GL_MAP_REVERSE[dep]) {
      componentsGLImports.push(dep);
    } else if (FEATURES.includes(dep)) {
      featuresImports.push(dep);
    } else if (EXTENSIONS_MAP[dep]) {
      extensionImports.push(dep);
    }
  });

  function getImportsPartCode(imports) {
    return `${imports
      .map(
        (str) => `
    ${str}`
      )
      .join(',')}`;
  }

  const allImports = [
    ...componentsImports,
    ...chartsImports,
    ...componentsGLImports,
    ...chartsGLImports,
    ...renderersImports,
    ...featuresImports
  ];

  const ECOptionTypeCode = `
type EChartsOption = echarts.ComposeOption<
    ${allImports.filter((a) => a.endsWith('Option')).join(' | ')}
>`;
  const importsCodes = [
    [componentsImports, 'echarts/components'],
    [chartsImports, 'echarts/charts'],
    [featuresImports, 'echarts/features'],
    [renderersImports, 'echarts/renderers'],
    [chartsGLImports, 'echarts-gl/charts'],
    [componentsGLImports, 'echarts-gl/components']
  ]
    .filter((a) => a[0].length > 0)
    .map((item) =>
      `
import {${getImportsPartCode(item[0])}
} from '${item[1]}';
    `.trim()
    );

  getExtensionDeps(extensionImports, includeType).forEach((ext) => {
    importsCodes.push(`import '${ext}';`);
  });

  return (
    `import * as echarts from 'echarts/core';
${importsCodes.join('\n')}

echarts.use(
    [${allImports.filter((a) => !a.endsWith('Option')).join(', ')}]
);
` + (includeType ? ECOptionTypeCode : '')
  );
}