Skip to content

Commit ab9349b

Browse files
author
xuyuanxiang@home
committed
fix: use api.modifyConfig to set mountElementId and history as RN's except
1 parent 0d27f66 commit ab9349b

File tree

5 files changed

+9
-16
lines changed

5 files changed

+9
-16
lines changed

README.md

+1-14
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,7 @@ _以下是`umi-preset-react-native`对 Node、react、react-native、umi 版本
5757

5858
### 配置
5959

60-
```javascript
61-
// .umirc.js
62-
export default {
63-
mountElementId: false,
64-
history: {
65-
type: 'memory',
66-
},
67-
};
68-
```
69-
70-
**注意:RN 环境中没有 DOM 和 BOM, 所以这两项配置为必填,需要覆盖[umi](https://umijs.org/)的默认值,避免运行时进入到调用 DOM/BOM API 的代码分支导致运行错误。**
71-
72-
- `mountElementId`[umi](https://umijs.org/) 默认值是:`'root'`,在 RN 中**必须覆盖为`false`或空字符串**
73-
- `history`[umi](https://umijs.org/) 默认值是:`'browser'`,在 RN 中**只能使用:`'memory'`类型**
60+
安装依赖后,开箱即用。零配置,直接使用缺省值即可。
7461

7562
> All dependencies start with @umijs/preset-@umijs/plugin-、umi-preset-、umi-plugin- will be registered as plugin/plugin-preset.
7663

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
testMatch: ['<rootDir>/packages/**/__tests__/**/*.[jt]s?(x)', '<rootDir>/packages/**/?(*.)+(spec|test).[tj]s?(x)'],
2+
testMatch: ['<rootDir>/packages/**/test/**/*.(spec|test).[jt]s?(x)'],
33
collectCoverageFrom: ['<rootDir>/packages/*/src/**/*.{ts,tsx}'],
44
coveragePathIgnorePatterns: ['/node_modules/', '<rootDir>/packages/*/lib/'],
55
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/packages/*/lib/'],

packages/preset/src/plugins/features/reactNative.ts

+6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ export default (api: IApi) => {
6363
},
6464
});
6565

66+
api.modifyConfig((config) => ({
67+
...config,
68+
mountElementId: false,
69+
history: { type: 'memory' },
70+
}));
71+
6672
// haul中没有treeShaking, mainFields 写死了。
6773
api.addProjectFirstLibraries(() => [
6874
{ name: 'react-native', path: REACT_NATIVE_PATH },

packages/runtime/tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"extends": "../../tsconfig",
33
"compilerOptions": {
4-
"jsx": "react",
54
"target": "ES5",
65
"module": "ES2015",
76
"rootDir": "src",

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"compilerOptions": {
3+
"jsx": "react",
34
"target": "es5",
45
"module": "commonjs",
56
"lib": ["esnext"],

0 commit comments

Comments
 (0)