in packages/build-plugin-lowcode/src/index.js [621:714]
async function bundleMetaV2(options, pluginOptions, execCompile, metaType) {
const { registerTask, getAllTask, onGetWebpackConfig, context } = options;
const { rootDir, pkg: package, userConfig = {} } = context;
if (!PARSED_NPM_NAME) {
PARSED_NPM_NAME = parseNpmName(package.name);
}
const metaExportName = `${PARSED_NPM_NAME.uniqueName}Meta`;
let { components } = pluginOptions || {};
const {
categories = DEFAULT_CATEGORIES,
externals = {},
basicLibraryVersion: customBasicLibraryVersion,
buildTarget = 'build',
fullbackMeta = 'default',
lowcodeDir = 'lowcode',
engineScope = '@ali',
npmInfo = {},
} = pluginOptions || {};
if (components && !Array.isArray(components)) {
console.error('[@alifd/build-plugin-lowcode] components must be Array<ComponentName: string>');
components = null;
}
const metaSuffix = metaType ? `.${metaType}` : '';
const metaFilename = `meta${metaSuffix}`;
let fullbackComponents;
let fullbackMetaSuffix;
if (fullbackMeta) {
fullbackMetaSuffix = fullbackMeta === 'default' ? '' : `.${fullbackMeta}`;
fullbackComponents = getUsedComponentMetas(
rootDir,
lowcodeDir,
`meta${fullbackMetaSuffix}`,
components,
);
}
const usedComponents = getUsedComponentMetas(
rootDir,
lowcodeDir,
`meta${metaSuffix}`,
components,
);
const componentsImportStr = fullbackComponents
.map((component) => {
const componentNameFolder = camel2KebabComponentName(component);
let metaJsPath = path.resolve(
rootDir,
`${lowcodeDir}/${componentNameFolder}/${metaFilename}`,
);
if (!usedComponents.includes(component) && fullbackComponents.includes(component)) {
metaJsPath = path.resolve(
rootDir,
`${lowcodeDir}/${componentNameFolder}/meta${fullbackMetaSuffix}`,
);
usedComponents.push(component);
}
metaJsPath = metaJsPath.replace(/\\/g, '\\\\')
return `import ${
component.includes('.') ? component.replace(/\./g, '') : component
}Meta from '${metaJsPath}'`;
})
.join('\n');
const metaPath = generateEntry({
template: 'meta.js',
filename: `meta${metaSuffix}.js`,
rootDir,
params: {
componentsImportStr,
components: usedComponents.map(
(component) => `${component.includes('.') ? component.replace(/\./g, '') : component}Meta`,
),
execCompile,
metaExportName,
categories: JSON.stringify(categories),
npmInfo: JSON.stringify(npmInfo || {}),
version: package.version,
packageName: package.name,
basicLibraryVersion: JSON.stringify(customBasicLibraryVersion || BASIC_LIBRARY_VERSION),
},
});
if (!execCompile || getAllTask().includes(`lowcode-meta-${metaType}`)) return metaPath;
registerTask(`lowcode-meta-${metaType}`, getWebpackConfig('production'));
onGetWebpackConfig(`lowcode-meta-${metaType}`, (config) => {
config.merge({
entry: {
[`meta${metaSuffix}`]: metaPath,
},
});
config.output.library(metaExportName).libraryTarget('umd');
config.output.path(path.resolve(rootDir, `${buildTarget}/${lowcodeDir}`));
config.externals({ ...COMMON_EXTERNALS_MAP[engineScope], ...externals });
useStyleLoader(config);
});
return metaPath;
}