Skip to content

Commit

Permalink
docs: add clarification to loader this.callback usage
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a committed Sep 10, 2024
1 parent 28f3e7a commit 79cfb17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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.
Without returning its value, for example `meta`, the next loader will not receive it.
:::

## 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。
当没有返回值时,例如 `meta`,下一个 loader 将不会收到它。
:::

## this.context

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

0 comments on commit 79cfb17

Please sign in to comment.