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 more exhaustive example on customized-loader #897

Merged
merged 2 commits into from Mar 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Expand Up @@ -319,7 +319,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 @@ -338,7 +339,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 @@ -349,8 +350,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 @@ -385,7 +386,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