Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
docs: add document for resolveLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a committed Aug 28, 2023
1 parent d07d0d0 commit aa151d2
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 2 deletions.
44 changes: 44 additions & 0 deletions docs/en/config/resolve-loader.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ApiMeta } from '../../../components/ApiMeta';

# ResolveLoader

<ApiMeta addedVersion="0.3.1" />

This configuration item is consistent in type with [`resolve`](/config/resolve), but this setting only affects the resolution of [loaders](/guide/loader).

- **Type:** Consistent with [`resolve`](/config/resolve)
- **Default:**

```js
{
conditionNames: ["loader", "require", "node"],
exportsFields: ["exports"],
mainFields: ["loader", "main"],
extensions: [".js"],
mainFiles: ["index"]
}
```

## Example

For instance, if you are developing a loader and want to showcase its usage from a user's perspective in an example, you can write:

```js title="rspack.config.js"
module.exports = {
resolveLoader: {
alias: {
'amazing-loader': require.resolve('path-to-your-amazing-loader'),
},
},
};
```

Then, in the example code, you can write:

```js
require('!!amazing-loader!./amazing-file.js');
```

::: info Inline Loaders
The loader mentioned above uses the syntax of inline loaders. For details, please refer to [here](/api/loader-api#inline-loaders).
:::
2 changes: 1 addition & 1 deletion docs/en/config/resolve.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ module.exports = config;
## resolve.fullySpecified

- **Type:** `boolean`
- **Default value:** `false`
- **Default:** `false`

No longer resolve extensions, no longer resolve mainFiles in package.json (but does not affect requests from mainFiles, browser, alias).

Expand Down
2 changes: 1 addition & 1 deletion docs/zh/api/loader-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = function (content, map, meta) {
};
```

## Inline loaders
## 内联 loader(Inline loaders)

可以在 `import` 语句中指定 Loader,或者任何同等的 "导入"方法。用 `!` 将 Loader 从资源中分离出来。每个部分都是相对于当前目录来解析的。

Expand Down
44 changes: 44 additions & 0 deletions docs/zh/config/resolve-loader.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ApiMeta } from '../../../components/ApiMeta';

# ResolveLoader

<ApiMeta addedVersion="0.3.1" />

该配置项和 [`resolve`](/config/resolve) 的类型保持一致,但这个配置仅会对 [loader](/guide/loader) 的解析生效。

- **类型:**[`resolve`](/config/resolve) 保持一致
- **默认值:**

```js
{
conditionNames: ["loader", "require", "node"],
exportsFields: ["exports"],
mainFields: ["loader", "main"],
extensions: [".js"],
mainFiles: ["index"]
}
```

## 示例

比如,你在进行 loader 的开发,但又希望能在 loader 的使用示例中以用户视角展示使用方式,你可以这样写:

```js title="rspack.config.js"
module.exports = {
resolveLoader: {
alias: {
'amazing-loader': require.resolve('path-to-your-amazing-loader'),
},
},
};
```

然后,在 example 的代码中这么写:

```js
require('!!amazing-loader!./amazing-file.js');
```

::: info 内联 loader
上述的 loader 使用的是内联 loader 的语法,详情请参考[这里](/api/loader-api#%E5%86%85%E8%81%94-loaderinline-loaders)
:::
4 changes: 4 additions & 0 deletions modern.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ function getSidebarConfig(lang: 'zh' | 'en'): Sidebar {
text: getText('Resolve 模块解析', 'Resolve'),
link: getLink('/config/resolve'),
},
{
text: getText('ResolveLoader Loader解析', 'ResolveLoader'),
link: getLink('/config/resolve-loader'),
},
{
text: getText('Node 全局变量', 'Node'),
link: getLink('/config/node'),
Expand Down

0 comments on commit aa151d2

Please sign in to comment.