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

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

Open
johlug opened this issue Sep 2, 2020 · 0 comments
Open

Comments

@johlug
Copy link

johlug commented Sep 2, 2020

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
          }
        }
      ]
    ]
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant