Skip to content

Commit

Permalink
Add more exhaustive example on customized-loader (#897)
Browse files Browse the repository at this point in the history
* docs(customized-loader): add more exhaustive example on customized-loader

* Apply suggestions from code review

Co-authored-by: Nicolò Ribaudo <[email protected]>

---------

Co-authored-by: Huáng Jùnliàng <[email protected]>
Co-authored-by: Nicolò Ribaudo <[email protected]>
  • Loading branch information
3 people authored Mar 29, 2023
1 parent a797c3b commit b3682fd
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ your `custom` callback function.
```js
// Export from "./my-custom-loader.js" or whatever you want.
module.exports = require("babel-loader").custom(babel => {
function myPlugin() {
// Extract the custom options in the custom plugin
function myPlugin(api, { opt1, opt2 }) {
return {
visitor: {},
};
Expand All @@ -342,7 +343,7 @@ module.exports = require("babel-loader").custom(babel => {
},

// Passed Babel's 'PartialConfig' object.
config(cfg) {
config(cfg, { customOptions }) {
if (cfg.hasFilesystemConfig()) {
// Use the normal config
return cfg.options;
Expand All @@ -353,8 +354,8 @@ module.exports = require("babel-loader").custom(babel => {
plugins: [
...(cfg.options.plugins || []),

// Include a custom plugin in the options.
myPlugin,
// Include a custom plugin in the options and passing it the customOptions object.
[myPlugin, customOptions],
],
};
},
Expand Down Expand Up @@ -389,7 +390,7 @@ Given the loader's options, split custom options out of `babel-loader`'s
options.


### `config(cfg: PartialConfig): Object`
### `config(cfg: PartialConfig, options: { source, customOptions }): Object`

Given Babel's `PartialConfig` object, return the `options` object that should
be passed to `babel.transform`.
Expand Down

0 comments on commit b3682fd

Please sign in to comment.