A modular CLI toolkit for React Native projects
npm install rnapp-create一个可模块化组合的 React Native 项目脚手架 CLI:初始化新项目、按需添加能力模块,并基于 app.json 同步原生配置(应用名、图标、版本等)。
- init :基于官方 RN CLI 创建项目,并可交互选择要安装的模块
- add :在已有 RN 项目中按需追加模块
- sync:基于 app.json 同步原生信息与图标资源
- Node.js:建议 >= 16
- macOS:仅当你使用 --pod 时需要(会执行 CocoaPods 相关安装)
- 直接使用(推荐)
``bash`
npx rnapp-create@latest init MyApp
- 全局安装
`bash`
npm i -g rnapp-create
rnapp-create init MyApp
`bash`
npx rnapp-create@latest init MyApp
可选参数:
`bash初始化后自动执行 npm install
npx rnapp-create@latest init MyApp --install
$3
在 RN 项目根目录执行:
`bash
npx rnapp-create@latest add
`已支持的
feature:-
alias:路径别名(@/)
- tailwind:NativeWind v4 + Reanimated
- web:React Native Web + Vite
- router:路由(React Navigation 相关)
- i18n:多语言
- store:状态管理(Hox)
- system-ui:系统 UI 能力
- assets:内置字体/图标资产,并生成同步脚本多数模块只会修改配置文件与
package.json 依赖声明,依赖安装需你自行执行:`bash
npm install --legacy-peer-deps
`$3
在 RN 项目根目录执行:
`bash
npx rnapp-create@latest sync
`sync 会读取项目根目录的 app.json 并同步:- Android:
app_name、applicationId、versionCode、versionName、usesCleartextTraffic、图标(含 adaptive icon)
- iOS:CFBundleDisplayName、PRODUCT_BUNDLE_IDENTIFIER、MARKETING_VERSION、CURRENT_PROJECT_VERSION、图标app.json 关键字段(最少需要 displayName):`json
{
"displayName": "My App",
"version": "1.0.0",
"buildNumber": "1",
"icon": "./src/assets/app-icons/icon.png",
"iconScale": 0.78,
"ios": {
"bundleIdentifier": "com.example.myapp",
"buildNumber": "1",
"icon": "./src/assets/app-icons/icon.png"
},
"android": {
"applicationId": "com.example.myapp",
"versionCode": 1,
"usesCleartextTraffic": false,
"icon": "./src/assets/app-icons/icon.png",
"roundIcon": "./src/assets/app-icons/icon.png",
"adaptiveIcon": {
"foregroundImage": "./src/assets/app-icons/adaptive-icon.png",
"backgroundColor": "#ffffff",
"foregroundScale": 0.6,
"backgroundScale": 1
}
}
}
`如果你安装了
assets 模块,会在项目中注入脚本:`bash
npm run sync
`它等价于:
`bash
npx rnapp-create sync && react-native-asset
`本仓库调试
在仓库根目录直接运行:
`bash
node scripts/cli.js
node scripts/cli.js init MyApp
node scripts/cli.js add router
node scripts/cli.js sync
`发布(维护者)
发包前建议先确认实际会被发布的文件:
`bash
npm pack --dry-run
`如果发现
DemoApp/ 等目录也被打进包里,建议在 package.json 增加 files 白名单或添加 .npmignore 进行排除。发布流程示例:
`bash
npm login
npm version patch
npm publish --access public
``