Skip to content
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

(fix): ensure Babel presets are merged #473

Merged
merged 1 commit into from
Feb 2, 2020
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
13 changes: 11 additions & 2 deletions src/babelPluginTsdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ export const babelPluginTsdx = babelPlugin.custom((babelCore: any) => ({
);

const babelOptions = config.options || {};
babelOptions.presets = babelOptions.presets || [];

const envIdx = (babelOptions.presets || []).findIndex((preset: any) =>
const envIdx = babelOptions.presets.findIndex((preset: any) =>
preset.file.request.includes('@babel/preset-env')
);

// if they use preset-env, merge their options with ours
if (envIdx !== -1) {
const preset = babelOptions.presets[envIdx];
babelOptions.presets[envIdx] = createConfigItem(
Expand All @@ -134,7 +136,8 @@ export const babelPluginTsdx = babelPlugin.custom((babelCore: any) => ({
}
);
} else {
babelOptions.presets = createConfigItems('preset', [
// if no preset-env, add it & merge with their presets
const defaultPresets = createConfigItems('preset', [
{
name: '@babel/preset-env',
targets: customOptions.targets,
Expand All @@ -143,6 +146,12 @@ export const babelPluginTsdx = babelPlugin.custom((babelCore: any) => ({
exclude: ['transform-async-to-generator', 'transform-regenerator'],
},
]);

babelOptions.presets = mergeConfigItems(
'preset',
defaultPresets,
babelOptions.presets
);
}

// Merge babelrc & our plugins together
Expand Down