Skip to content

Commit 2c0a218

Browse files
lobsterkatieAbhiPrasad
authored andcommitted
feat(build): Add option to build only specified bundle variants (#5145)
There are situations in which we really only need one version of a bundle rather than all versions, but right now there's no way to build one without building all of them. This adds the option to specify which bundles you need, defaulting to the current behavior of building all three types (regular, minified, and minified with logging) if particular ones aren't requested.
1 parent a41c4a8 commit 2c0a218

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

rollup/bundleHelpers.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
} from './plugins/index.js';
2121
import { mergePlugins } from './utils';
2222

23+
const BUNDLE_VARIANTS = ['.js', '.min.js', '.debug.min.js'];
24+
2325
export function makeBaseBundleConfig(options) {
2426
const { bundleType, entrypoints, jsVersion, licenseTitle, outputFileBase, packageSpecificConfig } = options;
2527

@@ -128,46 +130,45 @@ export function makeBaseBundleConfig(options) {
128130
* @param baseConfig The rollup config shared by the entire package
129131
* @returns An array of versions of that config
130132
*/
131-
export function makeBundleConfigVariants(baseConfig) {
133+
export function makeBundleConfigVariants(baseConfig, options = {}) {
134+
const { variants = BUNDLE_VARIANTS } = options;
135+
132136
const includeDebuggingPlugin = makeIsDebugBuildPlugin(true);
133137
const stripDebuggingPlugin = makeIsDebugBuildPlugin(false);
134138
const terserPlugin = makeTerserPlugin();
135139

136-
// The additional options to use for each variant we're going to create
137-
const variantSpecificConfigs = [
138-
{
140+
// The additional options to use for each variant we're going to create.
141+
const variantSpecificConfigMap = {
142+
'.js': {
139143
output: {
140144
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.js`,
141145
},
142146
plugins: [includeDebuggingPlugin],
143147
},
144-
// This variant isn't particularly helpful for an SDK user, as it strips logging while making no other minification
145-
// changes, so by default we don't create it. It is however very useful when debugging rollup's treeshaking, so it's
146-
// left here for that purpose.
147-
// {
148-
// output: { file: `${baseConfig.output.file}.no-debug.js`,
149-
// },
150-
// plugins: [stripDebuggingPlugin],
151-
// },
152-
{
148+
149+
'.min.js': {
153150
output: {
154151
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.min.js`,
155152
},
156153
plugins: [stripDebuggingPlugin, terserPlugin],
157154
},
158-
{
155+
156+
'.debug.min.js': {
159157
output: {
160158
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.debug.min.js`,
161159
},
162160
plugins: [terserPlugin],
163161
},
164-
];
162+
};
165163

166-
return variantSpecificConfigs.map(variant =>
167-
deepMerge(baseConfig, variant, {
164+
return variants.map(variant => {
165+
if (!BUNDLE_VARIANTS.includes(variant)) {
166+
throw new Error(`Unknown bundle variant requested: ${variant}`);
167+
}
168+
return deepMerge(baseConfig, variantSpecificConfigMap[variant], {
168169
// Merge the plugin arrays and make sure the end result is in the correct order. Everything else can use the
169170
// default merge strategy.
170171
customMerge: key => (key === 'plugins' ? mergePlugins : undefined),
171-
}),
172-
);
172+
});
173+
});
173174
}

0 commit comments

Comments
 (0)