| | |
| | | |
| | | * `customize`: Default `null`. The path of a module that exports a `custom` callback [like the one that you'd pass to `.custom()`](#customized-loader). Since you already have to make a new file to use this, it is recommended that you instead use `.custom` to create a wrapper loader. Only use this if you _must_ continue using `babel-loader` directly, but still want to customize. |
| | | |
| | | * `metadataSubscribers`: Default `[]`. Takes an array of context function names. E.g. if you passed ['myMetadataPlugin'], you'd assign a subscriber function to `context.myMetadataPlugin` within your webpack plugin's hooks & that function will be called with `metadata`. |
| | | |
| | | ## Troubleshooting |
| | | |
| | | ### babel-loader is slow! |
| | |
| | | { |
| | | test: /\.m?js$/, |
| | | exclude: { |
| | | test: /node_modules/, // Exclude libraries in node_modules ... |
| | | and: [/node_modules/], // Exclude libraries in node_modules ... |
| | | not: [ |
| | | // Except for a few of them that needs to be transpiled because they use modern syntax |
| | | /unfetch/, |
| | |
| | | } |
| | | ``` |
| | | |
| | | ### Top level function (IIFE) is still arrow (on Webpack 5) |
| | | |
| | | 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)). |
| | | |
| | | To avoid the top-level arrow function, you can use `output.environment.arrowFunction`: |
| | | |
| | | ```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. |