Skip to content

Instantly share code, notes, and snippets.

@loganfsmyth
Created December 1, 2017 23:16
Show Gist options
  • Save loganfsmyth/6a56adcf4f318251be99eb453d5b94bd to your computer and use it in GitHub Desktop.
Save loganfsmyth/6a56adcf4f318251be99eb453d5b94bd to your computer and use it in GitHub Desktop.
Short description of Babel's config merge for `.env`
{
sourceMaps: false,
comments: false,
plugins: [
["plg-one", {}],
["plg-two", {opt: false}],
],
env: {
development: {
sourceMaps: true,
plugins: [
["plg-two", { otheropt: true}],
["plg-three", {}],
],
}
}
}
{
sourceMaps: true,
comments: false,
plugins: [
["plg-one", {}],
["plg-two", { otheropt: true}],
["plg-three", {}],
],
}

Merging basically has three separate parts. One for general options flags (those that aren't plugins and presets), and one each for presets and plugins.

The env options merge on top of the root config, so in this example sourceMaps: true overwrites the root false, but the root's comments: false also still in effect, since nothing in env overrode it.

For plugins and presets, they essentially merge by name (in reality identity), so if you specify options for a plugin in env, and that plugin is already in the root, it'll overide it with the options from env. The unique plugins from the root and env will just get joined and you'll end up with three plugins total.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment