Skip to content

Commit b3682fd

Browse files
comoserJLHwungnicolo-ribaudo
authored
Add more exhaustive example on customized-loader (#897)
* 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]>
1 parent a797c3b commit b3682fd

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ your `custom` callback function.
323323
```js
324324
// Export from "./my-custom-loader.js" or whatever you want.
325325
module.exports = require("babel-loader").custom(babel => {
326-
function myPlugin() {
326+
// Extract the custom options in the custom plugin
327+
function myPlugin(api, { opt1, opt2 }) {
327328
return {
328329
visitor: {},
329330
};
@@ -342,7 +343,7 @@ module.exports = require("babel-loader").custom(babel => {
342343
},
343344

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

356-
// Include a custom plugin in the options.
357-
myPlugin,
357+
// Include a custom plugin in the options and passing it the customOptions object.
358+
[myPlugin, customOptions],
358359
],
359360
};
360361
},
@@ -389,7 +390,7 @@ Given the loader's options, split custom options out of `babel-loader`'s
389390
options.
390391

391392

392-
### `config(cfg: PartialConfig): Object`
393+
### `config(cfg: PartialConfig, options: { source, customOptions }): Object`
393394

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

0 commit comments

Comments
 (0)