npm install 后 React Native 自动更新第三方
React Native update third party automatically after npm install
我是 React Native 的新手。
是否可以在 npm install 后自动为第三方库设置正确的 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>
sed
的 if/else 是因为它在 macOS 和 linux 上有不同的签名。
我们项目中的 sed 示例:
$SED_CMD 's/#import <fishhook\/fishhook.h>/#import "fishhook.h"/' ./node_modules/react-native/Libraries/WebSocket/RCTReconnectingWebSocket.m
我是 React Native 的新手。 是否可以在 npm install 后自动为第三方库设置正确的 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>
sed
的 if/else 是因为它在 macOS 和 linux 上有不同的签名。
我们项目中的 sed 示例:
$SED_CMD 's/#import <fishhook\/fishhook.h>/#import "fishhook.h"/' ./node_modules/react-native/Libraries/WebSocket/RCTReconnectingWebSocket.m