Skip to content

documentation: Add example of passing options to a custom babel-preset #863

Open
@johlug

Description

@johlug

It took me a while to find out how to create a custom babel-preset, where I can pass options to it. It would be good if you can add an example to the documentation, in a way like this:

// babel-preset-myPreset on npm

module.exports = (api, opts) => {
  return {
    plugins: [
      "@babel/plugin-proposal-nullish-coalescing-operator",
      "@babel/plugin-proposal-optional-chaining"
    ],
    presets: [
      [
        "@babel/preset-env",
        {
          useBuiltIns: "entry",
          ...(opts && opts)
        }
      ]
    ]
  }
}

call in webpack configuration

// webpack configuratoin
{
  loader: 'babel-loader',
  options: {
    presets: [
      [
        'babel-preset-myPreset', {
          targets: {
            esmodules: true
          }
        }
      ]
    ]
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions