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: provide an example of adding a custom file loader configuration #12180

Closed
wants to merge 3 commits into from
Closed
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
13 changes: 12 additions & 1 deletion docs/docs/docs/api/plugin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ api.addHTMLHeadScripts(() => `console.log('I am in HTML-head')`)
通过 [webpack-chain](https://github.com/neutrinojs/webpack-chain) 的方式修改 webpack 配置。传入一个fn,该 fn 不需要返回值。它将接收两个参数:
- `memo` 对应 webpack-chain 的 config
- `args:{ webpack, env }` `arg.webpack` 是 webpack 实例, `args.env` 代表当前的运行环境。

e.g.
```ts
api.chainWebpack(( memo, { webpack, env}) => {
Expand All @@ -443,6 +442,18 @@ api.chainWebpack(( memo, { webpack, env}) => {
memo.plugins.delete('progess');
})
```
> 注意: 如果要添加自定义的文件类型相关 loader 请额外设置 `type: "javascript/auto"`,否则会命中兜底的 asset rule。示例如下:

```js
config.module
.rule('abc')
.test(/\.abc$/)
.type('javascript/auto') // 添加此行配置
.use('abc-loader')
.loader('abc-loader')
.end();
Copy link
Contributor

@fz6m fz6m Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样并不好,因为你的文件并不一定就是 js 相关的,可能是一些自定义格式或者 wasm 或 css 等相关的,直接在 asset 规则里排除你要处理的文件正则就行了,参考:wasm 配置 方法。

建议把这里的说明和示例改成配置自定义 loader + 去掉 asset 里的命中的形式。

```


### modifyAppData (`umi@4` 新增)

Expand Down
Loading