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

Add note about top-level IIFE to the 'Troubleshooting' section #886

Merged
merged 2 commits into from
Dec 15, 2020
Merged
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,24 @@ You will need to exclude them form `babel-loader`.
}
```

### Top level function (IIFE) is still arrow (on Webpack 5)

That function is defined not by loader, but by Webpack itself. You check or update discussion in [this issue](https://github.com/babel/babel-loader/issues/885). In short - type of the function is defined by `output.environment` in webpack configuration (check more details at [webpack documentation]((https://webpack.js.org/configuration/output/#outputenvironment)). So to have top level function as regular one you need to do next:
vvscode marked this conversation as resolved.
Show resolved Hide resolved

```js
// webpack.config.js
module.exports = {
// ...
output: {
// ...
environment: {
// ...
arrowFunction: false, // <-- this line does the trick
},
},
};
```

## Customize config based on webpack target

Webpack supports bundling multiple [targets](https://webpack.js.org/concepts/targets/). For cases where you may want different Babel configurations for each target (like `web` _and_ `node`), this loader provides a `target` property via Babel's [caller](https://babeljs.io/docs/en/config-files#apicallercb) API.
Expand Down