This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add document for
resolveLoader
- Loading branch information
Showing
5 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters