call `bundle.close` when done generating Rollup bundles
#1,488 创建于 2025年4月12日
仓库指标
- 星标
- (132 个星标)
- PR 合并指标
- (平均合并 25天 20小时) (30 天内合并 29 个 PR)
描述
Current State
Currently when generating bundles with Rollup in packages/cli/src/lifecycles/bundle.js, we simply call bundle.write and we're done, e.g.
async function bundleApiRoutes(compilation) {
const apiConfigs = await getRollupConfigForApiRoutes(compilation);
if (apiConfigs.length > 0 && apiConfigs[0].input.length !== 0) {
console.info("bundling API routes...");
for (const configIndex in apiConfigs) {
const rollupConfig = apiConfigs[configIndex];
const bundle = await rollup(rollupConfig);
await bundle.write(rollupConfig.output);
}
}
}
Desired State
Was reading the Rollup docs the other day and saw that they recommend calling bundle.write when done
Once you're finished with the bundle object, you should call
bundle.close(), which will let plugins clean up their external processes or services via thecloseBundlehook.
So for all three places in bundle.js where we are calling bundle.write (SSR pages, API routes, Browser scripts), we should add a bundle.close call
const rollupConfig = apiConfigs[configIndex];
const bundle = await rollup(rollupConfig);
await bundle.write(rollupConfig.output);
await bundle.close();
I'm assuming
bundle.closeisasyncbut might be good to confirm, though I think we'll need to look at the code, since I don't think it was obvious from the docs.
Additional Context
No response