Skip to content

Commit 93efe6d

Browse files
committed
chore: doc the import_mode
1 parent 397baeb commit 93efe6d

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

packages/rspack/src/config/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,8 +1149,9 @@ export type AssetInlineGeneratorOptions = {
11491149
export type AssetModuleOutputPath = Filename;
11501150

11511151
/**
1152-
* If "url", generate url for asset based on `publicPath`
1153-
* If "preserve", preserve import statement from generated asset
1152+
* If "url", a URL pointing to the asset will be generated based on publicPath.
1153+
* If "preserve", preserve import/require statement from generated asset.
1154+
* Only for modules with module type 'asset' or 'asset/resource'.
11541155
* @default "url"
11551156
*/
11561157
export type AssetModuleImportMode = "url" | "preserve";

website/docs/en/config/module.mdx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,44 @@ When set to 'base64', module source will be encoded using Base64 algorithm. Sett
486486

487487
A mimetype for data URI. Resolves from module resource extension by default. Only for modules with module type `'asset'` or `'asset/inline'`.
488488

489+
#### module.generator.asset.importMode
490+
491+
- **Type:** `'url' | 'preserve'`
492+
- **Default:** `'url'`
493+
494+
If `"url"`, a URL pointing to the asset will be generated based on [publicPath](#modulegeneratorassetpublicPath).
495+
If `"preserve"`, preserve import/require statement from generated asset.
496+
497+
Only for modules with module type `'asset'` or `'asset/resource'`.
498+
499+
- `'asset'`:
500+
501+
```js title=rspack.config.js
502+
module.exports = {
503+
module: {
504+
generator: {
505+
asset: {
506+
importMode: 'preserve',
507+
},
508+
},
509+
},
510+
};
511+
```
512+
513+
- `'asset/resource'`:
514+
515+
```js title=rspack.config.js
516+
module.exports = {
517+
module: {
518+
generator: {
519+
'asset/resource': {
520+
importMode: 'preserve',
521+
},
522+
},
523+
},
524+
};
525+
```
526+
489527
#### module.generator.asset.filename
490528

491529
- **Type:** `string | ((pathData: PathData, assetInfo?: AssetInfo) => string)`

website/docs/zh/config/module.mdx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,44 @@ module.exports = {
486486

487487
dataUrl 的 MIME 类型,默认从模块资源扩展名解析。仅对模块类型为 `'asset/inline'` 的模块生效。
488488

489+
#### module.generator.asset.importMode
490+
491+
- **类型:** `'url' | 'preserve'`
492+
- **默认值:** `'url'`
493+
494+
如果为 `"url"`,将基于 [publicPath](#modulegeneratorassetpublicPath) 生成指向 asset 的 URL。
495+
如果为 `"preserve"`,将保留指向生成的 asset 的 import 或 require 语句。
496+
497+
仅对模块类型为 `'asset'``'asset/resource'` 的模块生效。
498+
499+
- `'asset'`:
500+
501+
```js title=rspack.config.js
502+
module.exports = {
503+
module: {
504+
generator: {
505+
asset: {
506+
importMode: 'preserve',
507+
},
508+
},
509+
},
510+
};
511+
```
512+
513+
- `'asset/resource'`:
514+
515+
```js title=rspack.config.js
516+
module.exports = {
517+
module: {
518+
generator: {
519+
'asset/resource': {
520+
importMode: 'preserve',
521+
},
522+
},
523+
},
524+
};
525+
```
526+
489527
#### module.generator.asset.filename
490528

491529
- **类型:** `string | ((pathData: PathData, assetInfo?: AssetInfo) => string)`

0 commit comments

Comments
 (0)