react-native - npm install 后 React Native 自动更新第三方
问题描述
我是反应原生的新手。是否可以在 npm 安装后自动为第三方库设置正确的 sdk 版本或其他内容?因为有时当我搞砸项目并且代码无法回滚时,我会删除它并从 git 克隆项目。但这就是问题所在,因为android库sdk版本和ios库搜索路径不正确,需要我自己更正。
解决方案
添加postinstall
到 package.json 脚本中。这将在安装运行后自动运行:
"postinstall": "./edit_modules.sh",
并在项目根目录中创建一个edit_modules.sh
文件。像这样的东西:
#!/bin/bash
if [[ "$OSTYPE" == "darwin"* ]]; then
SED_CMD="sed -i ''"
else
SED_CMD="sed -i"
fi
$SED_CMD 's/<pattern to find>/<replace with>/' <path to file relative to root>
if/else forsed
是因为它在 macOS 和 linux 上具有不同的签名。
以及我们项目中的示例 sed:
$SED_CMD 's/#import <fishhook\/fishhook.h>/#import "fishhook.h"/' ./node_modules/react-native/Libraries/WebSocket/RCTReconnectingWebSocket.m
推荐阅读
- node.js - Express - res.download 无法正常工作
- sql - Oracle Sql 一次更新多条记录?
- javascript - 除非接收到用户交互,否则 iframe 不会处于活动状态
- r - 将外部函数(和参数)传递给 dplyr 汇总或变异
- angular - 从 http 标头选项导入并在 Angular 上弃用请求
- python - Selenium 脚本不打印 XPath 值
- excel - 用基于另一个单元格的公式填充列
- c# - 类不变量以确保字段上的特定数据类型不成立
- excel - Excel 2010 中的冷冻切片机
- karate - #ignore 和#present 是一回事吗?