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

feat(mf): 新增remoteHash参数控制mf的产物是否启用hash(#11711) #11714

Merged
merged 6 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
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: 13 additions & 0 deletions docs/docs/docs/max/mf.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ src/exposes/
}
```

### 关闭 MF 产物 hash

默认情况下,当用户开启 `hash: true` 时, MF 产物中入口文件将自动携带 hash ,如 `remote.123abc.js` ,可通过设定 `remoteHash: false` 关闭(将得到 `remote.js` ),此时你可能需要修改 nginx / CDN / 网关 的响应头配置来去除该 `remote.js` 文件的缓存,否则新构建将无法生效。
fz6m marked this conversation as resolved.
Show resolved Hide resolved

注:没有 hash 的更多危害与推荐做法详见 [issue #11711](https://github.com/umijs/umi/issues/11711)


```ts
mf: {
remoteHash: false
}
```

## 运行时 API

### 何时需要使用运行时 API ?
Expand Down
5 changes: 4 additions & 1 deletion packages/plugins/src/mf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function mf(api: IApi) {
),
shared: zod.record(zod.any()),
library: zod.record(zod.any()),
remoteHash: zod.boolean(),
})
.partial();
},
Expand Down Expand Up @@ -70,7 +71,9 @@ export default function mf(api: IApi) {
);
}

const useHash = api.config.hash && api.env !== 'development';
const useHash = typeof api.config.mf.remoteHash === 'boolean'
? api.config.mf.remoteHash
: (api.config.hash && api.env !== 'development');

const mfConfig = {
name,
Expand Down
Loading