Skip to content

feat(build): Add option to build only specified bundle variants #5145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions rollup/bundleHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
} from './plugins/index.js';
import { mergePlugins } from './utils';

const BUNDLE_VARIANTS = ['.js', '.min.js', '.debug.min.js'];

export function makeBaseBundleConfig(options) {
const { bundleType, entrypoints, jsVersion, licenseTitle, outputFileBase, packageSpecificConfig } = options;

Expand Down Expand Up @@ -128,46 +130,45 @@ export function makeBaseBundleConfig(options) {
* @param baseConfig The rollup config shared by the entire package
* @returns An array of versions of that config
*/
export function makeBundleConfigVariants(baseConfig) {
export function makeBundleConfigVariants(baseConfig, options = {}) {
const { variants = BUNDLE_VARIANTS } = options;

const includeDebuggingPlugin = makeIsDebugBuildPlugin(true);
const stripDebuggingPlugin = makeIsDebugBuildPlugin(false);
const terserPlugin = makeTerserPlugin();

// The additional options to use for each variant we're going to create
const variantSpecificConfigs = [
{
// The additional options to use for each variant we're going to create.
const variantSpecificConfigMap = {
'.js': {
output: {
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.js`,
},
plugins: [includeDebuggingPlugin],
},
// This variant isn't particularly helpful for an SDK user, as it strips logging while making no other minification
// changes, so by default we don't create it. It is however very useful when debugging rollup's treeshaking, so it's
// left here for that purpose.
// {
// output: { file: `${baseConfig.output.file}.no-debug.js`,
// },
// plugins: [stripDebuggingPlugin],
// },
{

'.min.js': {
output: {
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.min.js`,
},
plugins: [stripDebuggingPlugin, terserPlugin],
},
{

'.debug.min.js': {
output: {
entryFileNames: chunkInfo => `${baseConfig.output.entryFileNames(chunkInfo)}.debug.min.js`,
},
plugins: [terserPlugin],
},
];
};

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