async function bundleRenderView()

in packages/build-plugin-lowcode/src/index.js [927:1007]


async function bundleRenderView(options, pluginOptions, platform, execCompile) {
  const { registerTask, getAllTask, onGetWebpackConfig } = options;
  const { rootDir, pkg: package } = options.context;
  if (!PARSED_NPM_NAME) {
    PARSED_NPM_NAME = parseNpmName(package.name);
  }
  const {
    library = PARSED_NPM_NAME.uniqueName,
    umdUrls,
    editUrls,
    baseLibrary = 'react',
    components,
    externals = {},
    buildTarget = 'build',
    lowcodeDir = 'lowcode',
    engineScope = '@ali',
    entryPath,
  } = pluginOptions || {};
  let componentViews;
  let componentViewsExportStr;
  let componentViewsImportStr;
  const _componentViews =
    getUsedComponentViews(rootDir, `src/${platform}/components`, components) || [];
  console.log('_componentViews: ', _componentViews);
  componentViews = `{${_componentViews
    .map((component) => {
      return `${component}: ${component}`;
    })
    .join(',')}}`;
  componentViewsExportStr = _componentViews
    .map((component) => {
      return `const ${component} = getRealComponent(${component}Data, '${component}');\nexport { ${component} };`;
    })
    .join('\n');
  const exportPath = `\nexport { default } from '${getEntry(rootDir, entryPath)}';`;
  componentViewsExportStr += exportPath.includes('\\\\') ? exportPath : exportPath.replace(/\\/g, '\\\\');
  componentViewsImportStr = _componentViews
    .map((component) => {
      const componentNameFolder = camel2KebabComponentName(component);
      const viewJsPath = getEntry(
        rootDir,
        `src/${platform}/components/${componentNameFolder}/view`,
      );
      return `import * as ${component}Data from '${viewJsPath}'`;
    })
    .join('\n');
  const scssEntry = getScssEntry(rootDir);
  const viewPath = generateEntry({
    template: 'view.js',
    filename: `${platform}.view.js`,
    rootDir,
    params: {
      entryPath: getEntry(rootDir, entryPath),
      scssImport: scssEntry ? `import '${scssEntry}'` : '',
      componentViews,
      componentViewsExportStr,
      componentViewsImportStr,
      library,
      execCompile,
    },
  });
  if (!execCompile || editUrls || umdUrls || getAllTask().includes(`render-view-${platform}`))
    return viewPath;
  registerTask(`render-view-${platform}`, getWebpackConfig('production'));
  onGetWebpackConfig(`render-view-${platform}`, (config) => {
    debug('render view build: ', viewPath);
    config.merge({
      entry: {
        view: viewPath,
      },
    });
    config.output.library(library).libraryTarget('umd');
    config.output.path(path.resolve(rootDir, `${buildTarget}/${lowcodeDir}/render/${platform}`));
    config.externals({ ...COMMON_EXTERNALS_MAP[engineScope], ...externals });
    if (baseLibrary === 'rax') {
      const scssRule = config.module.rule('scss');
      scssRule.use('rpx-loader').loader('rpx-loader').before('css-loader');
    }
  });
  return viewPath;
}