Skip to content

Commit 1669ac0

Browse files
Add note about top-level IIFE to the 'Troubleshooting' section (#886)
* Add note about top-level IIFE to the 'Troubleshooting' section * Update README.md Co-authored-by: Nicolò Ribaudo <[email protected]> Co-authored-by: Nicolò Ribaudo <[email protected]>
1 parent 649f578 commit 1669ac0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,26 @@ You will need to exclude them form `babel-loader`.
250250
}
251251
```
252252

253+
### Top level function (IIFE) is still arrow (on Webpack 5)
254+
255+
That function is injected by Webpack itself _after_ running `babel-loader`. By default Webpack asumes that your target environment supports some ES2015 features, but you can overwrite this behavior using the `output.environment` Webpack option ([documentation]((https://webpack.js.org/configuration/output/#outputenvironment)).
256+
257+
To avoid the top-level arrow function, you can use `output.environment.arrowFunction`:
258+
259+
```js
260+
// webpack.config.js
261+
module.exports = {
262+
// ...
263+
output: {
264+
// ...
265+
environment: {
266+
// ...
267+
arrowFunction: false, // <-- this line does the trick
268+
},
269+
},
270+
};
271+
```
272+
253273
## Customize config based on webpack target
254274

255275
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.

0 commit comments

Comments
 (0)