-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rn不能import表达式,改为运行npm前生成js文件 用于路由引用
- Loading branch information
Showing
7 changed files
with
79 additions
and
47 deletions.
There are no files selected for viewing
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,29 @@ | ||
// react native在import时路径不能使用字符串拼接形式,用脚本生成一份router配置 | ||
const prettier = require('prettier'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const prettierRc = require('../../.prettierrc.js'); | ||
const componentConfig = require('../src/config.json'); | ||
|
||
console.log('正在生成路由文件...'); | ||
const keys = []; | ||
componentConfig.forEach((config) => { | ||
config?.children?.forEach((child) => { | ||
keys.push(child.key); | ||
}); | ||
}); | ||
|
||
const code = `import { lazy, LazyExoticComponent } from 'react'; | ||
const componentsMap: Record<string, LazyExoticComponent<() => JSX.Element>> = { | ||
${keys.map((key) => `${key}: lazy(() => import('@src/components/${key}/_example/index'))`)} | ||
} | ||
export default componentsMap | ||
`; | ||
const formattedCode = prettier.format(code, { | ||
...prettierRc, | ||
parser: 'babel', | ||
}); | ||
|
||
fs.writeFileSync(path.resolve(__dirname, '../src/componentList.ts'), formattedCode, { encoding: 'utf-8' }); | ||
console.log('已生成路由文件👏🏻'); |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[ | ||
{ | ||
"title": "基础组件", | ||
"children": [ | ||
{ | ||
"title": "Base 基础容器", | ||
"key": "Base" | ||
}, | ||
{ | ||
"title": "Button 按钮", | ||
"key": "Button" | ||
} | ||
] | ||
}, | ||
{ | ||
"title": "布局", | ||
"children": [] | ||
}, | ||
{ | ||
"title": "导航", | ||
"children": [] | ||
}, | ||
{ | ||
"title": "输入", | ||
"children": [] | ||
}, | ||
{ | ||
"title": "数据展示", | ||
"children": [] | ||
}, | ||
{ | ||
"title": "消息提醒", | ||
"children": [] | ||
} | ||
] |
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