Skip to content

Commit b0c565d

Browse files
committed
add option to specify bundle variants to build
1 parent 45c618a commit b0c565d

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

rollup/bundleHelpers.js

Lines changed: 20 additions & 10 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,37 +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
},
148+
149+
'.min.js': {
144150
output: {
145151
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.min.js`,
146152
},
147153
plugins: [stripDebuggingPlugin, terserPlugin],
148154
},
149-
{
155+
156+
'.debug.min.js': {
150157
output: {
151158
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.debug.min.js`,
152159
},
153160
plugins: [terserPlugin],
154161
},
155-
];
162+
};
156163

157-
return variantSpecificConfigs.map(variant =>
158-
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], {
159169
// Merge the plugin arrays and make sure the end result is in the correct order. Everything else can use the
160170
// default merge strategy.
161171
customMerge: key => (key === 'plugins' ? mergePlugins : undefined),
162-
}),
163-
);
172+
});
173+
});
164174
}

0 commit comments

Comments
 (0)