Skip to content

Commit 8690594

Browse files
nicohrubeccodex
andcommitted
build: reuse debug bundle builds for minified output
Generate unminified and minified debug bundles from one Rollup build, retaining a separate production build and the existing output plugin order. Co-Authored-By: GPT-6 <codex@openai.com>
1 parent 1a5eff7 commit 8690594

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

‎dev-packages/rollup-utils/bundleHelpers.mjs‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ export function makeBaseBundleConfig(options) {
142142
* @param baseConfig The rollup config shared by the entire package
143143
* @returns An array of versions of that config
144144
*/
145-
export function makeBundleConfigVariants(baseConfig, options = {}) {
146-
const { variants = BUNDLE_VARIANTS } = options;
147-
145+
export function makeBundleConfigVariants(baseConfig) {
148146
const includeDebuggingPlugin = makeIsDebugBuildPlugin(true);
149147
const stripDebuggingPlugin = makeIsDebugBuildPlugin(false);
150148
const terserPlugin = makeTerserPlugin();
@@ -174,14 +172,22 @@ export function makeBundleConfigVariants(baseConfig, options = {}) {
174172
},
175173
};
176174

177-
return variants.map(variant => {
178-
if (!BUNDLE_VARIANTS.includes(variant)) {
179-
throw new Error(`Unknown bundle variant requested: ${variant}`);
180-
}
181-
return deepMerge(baseConfig, variantSpecificConfigMap[variant], {
175+
const [debug, production, minifiedDebug] = BUNDLE_VARIANTS.map(variant =>
176+
deepMerge(baseConfig, variantSpecificConfigMap[variant], {
182177
// Merge the plugin arrays and make sure the end result is in the correct order. Everything else can use the
183178
// default merge strategy.
184179
customMerge: key => (key === 'plugins' ? mergePlugins : undefined),
185-
});
186-
});
180+
}),
181+
);
182+
183+
const isOutputPlugin = plugin => ['terser', 'license'].includes(plugin.name);
184+
185+
debug.output = [debug, minifiedDebug].map(config => ({
186+
...config.output,
187+
plugins: config.plugins.filter(isOutputPlugin),
188+
}));
189+
190+
debug.plugins = debug.plugins.filter(plugin => !isOutputPlugin(plugin));
191+
192+
return [debug, production];
187193
}

0 commit comments

Comments
 (0)