UNPKG

zephyr-rsbuild-plugin

Version:

Rsbuild plugin for Zephyr

49 lines (48 loc) • 2.22 kB
import "node:module"; import { ZephyrEngine, assertZephyrBuildTarget } from "zephyr-agent"; import { withZephyr } from "zephyr-rspack-plugin"; import { coordinateXPackCompilers } from "zephyr-xpack-internal"; function with_zephyr_withZephyr(options) { const target = options?.target; if (void 0 !== target) assertZephyrBuildTarget(target, 'withZephyr({ target })'); return { name: 'zephyr-rsbuild-plugin', setup (api) { api.onBeforeCreateCompiler({ order: 'post', handler: async ({ bundlerConfigs })=>{ if (0 === bundlerConfigs.length) return; const engine = await ZephyrEngine.create({ builder: 'rspack', context: bundlerConfigs[0]?.context, target }); if (void 0 !== target) engine.env.target = target; try { const { coordinator, compilers } = coordinateXPackCompilers(engine, bundlerConfigs, { snapshotType: options?.snapshotType, entrypoint: options?.entrypoint }); for (const [index, config] of bundlerConfigs.entries()){ const rspackConfig = config; const result = await withZephyr({ ...options, target, __engine: engine, __coordinator: coordinator, __participant: compilers[index]?.participant, __assetPrefix: compilers[index]?.assetPrefix })(rspackConfig); if (result) Object.assign(config, result); } } catch (error) { if (engine.hasActiveBuild) engine.build_failed(); throw error; } } }); } }; } export { with_zephyr_withZephyr as withZephyr }; //# sourceMappingURL=with-zephyr.mjs.map