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

docs: add clarification to loader this.callback usage #7855

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions website/docs/en/api/loader-api/context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ A function that can be called synchronously or asynchronously in order to return
3. The third parameter is a source map that can be processed by the loader.
4. The fourth parameter is ignored by Rspack and can be anything (e.g. some metadata).

:::warning
In case this function is called, you should return `undefined` to avoid ambiguous loader results.

The value passed to `this.callback` will be passed to the next loader in the chain.
The `sourceMap` and `meta` parameters are optional. If they are not passed, the next loader will not receive them.
:::

## this.clearDependencies()

```ts
Expand Down
7 changes: 7 additions & 0 deletions website/docs/zh/api/loader-api/context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ function callback(

第一个参数必须是 `Error` 或者 `null`,会标记当前模块为编译失败,第二个参数是一个 `string` 或者 `Buffer`,表示模块被该 Loader 处理后的文件内容,第三个参数是一个可以该 Loader 处理后的 source map,第四个参数会被 Rspack 忽略,可以是任何东西(例如一些元数据)。

:::warning
当这个函数被调用时,你应该返回 `undefined` 以避免 loader 结果的歧义。

传递给 `this.callback` 的值会传递给下一个 loader。
`sourceMap` 和 `meta` 参数是可选的,如果没有传递,那么下一个 loader 将不会收到它们。
:::

## this.context

当前模块所在的目录。
Expand Down
Loading