Skip to content

Commit ad49ec4

Browse files
author
徐远翔
committed
feat: @umijs/plugin-dva
1 parent 12171ee commit ad49ec4

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323

2424
RN 示例工程:[UMIRNExample](https://github.com/xuyuanxiang/UMIRNExample)
2525

26-
- [compare/0.0.1...0.1.0](https://github.com/xuyuanxiang/UMIRNExample/compare/0.0.1...0.1.0):使用`react-native init`初始化工程 到 集成 `umi-preset-react-native` 后的改动内容。
26+
- [0.0.1](https://github.com/xuyuanxiang/UMIRNExample/tree/0.0.1): 使用`react-native init`得到的初始工程
27+
- [0.1.0](https://github.com/xuyuanxiang/UMIRNExample/tree/0.1.0):添加`umi`依赖并集成`umi-preset-react-native`
28+
- [compare/0.0.1...0.1.0](https://github.com/xuyuanxiang/UMIRNExample/compare/0.0.1...0.1.0)
29+
- [1.0.0](https://github.com/xuyuanxiang/UMIRNExample/tree/1.0.0):集成`@umijs/plugin-dva`
30+
- [compare/0.0.1...1.0.0](https://github.com/xuyuanxiang/UMIRNExample/compare/0.0.1...1.0.0)
31+
- [compare/0.1.0...1.0.0](https://github.com/xuyuanxiang/UMIRNExample/compare/0.1.0...1.0.0)
2732

2833
## 安装
2934

@@ -66,7 +71,7 @@ export default {
6671

6772
- `history`:在 RN 中只能使用:`'memory'`类型,[umi](https://umijs.org/) 默认值是:`'browser'``'browser'``'hash'`类型都需要 DOM,在 RN 中会报错;
6873

69-
_umi 3.x 后会自动探测宿主工程`devDependencies``dependencies`中所有含`umi-preset-``umi-plugin-`前缀的 npm 包,自动装配。所以不再需要在`.umirc.js`中配置`plugins``presets`_
74+
_umi 3.x 后会自动探测宿主工程`devDependencies``dependencies`并自动装配插件。所以不需要在`.umirc.js`中配置`plugins``presets`选项。_
7075

7176
**在 RN 中集成其他[umi](https://umijs.org/)插件需要开发者自行斟酌。**
7277

packages/preset/src/plugins/generateFiles/haulConfig.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const transform = ({ config }) => {
1313
export default makeConfig({
1414
bundles: {
1515
index: {
16-
entry: withPolyfills('./index.js'),
16+
entry: withPolyfills('./index.ts'),
1717
transform,
1818
},
1919
},
@@ -49,7 +49,7 @@ export default (api: IApi) => {
4949
return bundleConfig.entry?.umi;
5050
})[0];
5151

52-
const alias = lodash.omit(config.resolve?.alias, ['react-dom']);
52+
const alias = lodash.cloneDeep(config.resolve?.alias);
5353
Object.assign(alias, {
5454
// 防止加载umi Common JS格式的代码
5555
umi: winPath(join(absTmpPath || '', 'rn', 'umi')),

packages/preset/src/plugins/generateFiles/index.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default (api: IApi) => {
1919

2020
api.onGenerateFiles(async () => {
2121
api.writeTmpFile({
22-
path: 'index.js',
22+
path: 'index.ts',
2323
content: Mustache.render(indexTpl, {
2424
appKey: api.config?.reactNative?.appKey,
2525
entryCode: (
@@ -36,6 +36,13 @@ export default (api: IApi) => {
3636
initialValue: [],
3737
})
3838
).join('\r\n'),
39+
polyfillImports: importsToStr(
40+
await api.applyPlugins({
41+
key: 'addPolyfillImports',
42+
type: api.ApplyPluginsType.add,
43+
initialValue: [],
44+
}),
45+
).join('\r\n'),
3946
importsAhead: importsToStr(
4047
await api.applyPlugins({
4148
key: 'addEntryImportsAhead',
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
export default `
1+
export default `// @ts-ignore
22
if (global.window === undefined) {
3+
// @ts-ignore
34
global.window = global;
45
}
5-
6+
{{{ polyfillImports }}}
67
{{{ importsAhead }}}
78
import {ApplyPluginsType} from 'umi-react-native-runtime';
89
import {renderClient} from 'umi-react-native-renderer';
9-
import {plugin, history} from './core/umiExports';
10+
import {plugin} from './core/umiExports';
11+
import {createHistory} from './core/history';
1012
import {routes} from './core/routes';
1113
{{{ imports }}}
1214
1315
{{{ entryCodeAhead }}}
1416
15-
const getClientRender = (args = {}) => plugin.applyPlugins({
17+
const getClientRender = (args: { hot?: boolean } = {}) => plugin.applyPlugins({
1618
key: 'render',
1719
type: ApplyPluginsType.compose,
1820
initialValue: () => {
1921
return renderClient({
2022
routes,
2123
plugin,
22-
history,
24+
history: createHistory(args.hot),
2325
appKey: '{{{ appKey }}}',
2426
});
2527
},
@@ -32,4 +34,13 @@ export default clientRender();
3234
3335
{{{ entryCode }}}
3436
37+
// hot module replacement
38+
// @ts-ignore
39+
if (module.hot) {
40+
// @ts-ignore
41+
module.hot.accept(() => {
42+
getClientRender({ hot: true })();
43+
});
44+
}
45+
3546
`;

packages/preset/src/plugins/generateFiles/rn/umi.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export * from '../core/umiExports';
1414
export default (api: IApi) => {
1515
api.onGenerateFiles(async () => {
1616
api.writeTmpFile({
17-
path: 'rn/umi.js',
17+
path: 'rn/umi.ts',
1818
content: CONTENT,
1919
});
2020
});

0 commit comments

Comments
 (0)