babel / babel/babel-loader

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

Open
#863 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
4.8k
Forks
456
Avg merge
9h 19m
Merged PRs (30d)
2

Description

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:
```javascript
// 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
```javascript
// webpack configuratoin
{
loader: 'babel-loader',
options: {
presets: [
[
'babel-preset-myPreset', {
targets: {
esmodules: true
}
}
]
]
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.