-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
119 changed files
with
13,473 additions
and
3,130 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
// hide mf related docs | ||
.dumi-default-sidebar-group { | ||
a[href="/docs/guides/mfsu"], | ||
a[href="/en-US/docs/guides/mfsu"], | ||
a[href="/docs/max/mf"], | ||
a[href="/en-US/docs/max/mf"] { | ||
display: none; | ||
} | ||
} |
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 @@ | ||
export { default } from '.'; |
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,17 @@ | ||
import { useLayoutEffect } from 'react'; | ||
|
||
interface IHashAnchorCompatProps { | ||
from: string; | ||
to: string; | ||
} | ||
|
||
export default function HashAnchorCompat({ from, to }: IHashAnchorCompatProps) { | ||
useLayoutEffect(() => { | ||
const hash = window.location.hash; | ||
if (hash === from) { | ||
window.location.hash = to; | ||
} | ||
}, []); | ||
|
||
return null; | ||
} |
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,50 @@ | ||
--- | ||
toc: content | ||
order: 5 | ||
group: | ||
title: Blog | ||
--- | ||
|
||
# 代码拆分指南 | ||
|
||
Umi 4 默认 按页拆包、按需加载(这近似等同于 Umi 3 中的 `dynamicImport`),通过 [`loading.tsx`](../docs/guides/directory-structure#loadingtsxjsx) 来自定义加载动画。 | ||
|
||
### 使用分包策略 | ||
|
||
Umi 4 内置了不同的代码拆分策略 ( [codeSplitting](../docs/api/config#codesplitting) ) ,通过配置开启: | ||
|
||
```ts | ||
// .umirc.ts | ||
export default { | ||
codeSplitting: { | ||
jsStrategy: 'granularChunks', | ||
}, | ||
}; | ||
``` | ||
|
||
这会按照一定的优化策略进行自动分包,若需手动进行更细致的分包,请参见下文。 | ||
|
||
### 手动拆分 | ||
|
||
当你的产物体积变大时,可进一步手动拆包: | ||
|
||
```ts | ||
import { lazy, Suspense } from 'react' | ||
|
||
// './Page' 该组件将被自动拆出去 | ||
const Page = lazy(() => import('./Page')) | ||
|
||
export default function() { | ||
return ( | ||
<Suspense fallback={<div>loading...</div}> | ||
<Page /> | ||
</Suspense> | ||
) | ||
} | ||
``` | ||
|
||
通常情况下,我们会手动拆分引用了较大第三方库的组件,实现按需加载。 | ||
|
||
### 分析产物构成 | ||
|
||
通过指定 [ANALYZE](../docs/guides/env-variables#analyze) 环境变量可以分析产物构成,根据分析结果来修改代码和进一步决策。 |
Oops, something went wrong.