在React Native团队中使用git

时间:2018-07-19 12:01:00

标签: git react-native

我当前的.gitignore文件具有:

# OSX
# .DS_Store

# Xcode
# build/
*.pbxuser !default.pbxuser
*.mode1v3 !default.mode1v3
*.mode2v3 !default.mode2v3
*.perspectivev3 !default.perspectivev3 xcuserdata
*.xccheckout
*.moved-aside DerivedData
*.hmap
*.ipa
*.xcuserstate project.xcworkspace

# Android/IntelliJ
# build/ .idea .gradle local.properties
*.iml

# node.js
node_modules/ npm-debug.log yarn-error.log

# BUCK buck-out/ \.buckd/
*.keystore

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots

# Bundle artifact
*.jsbundle

#React Files
android/
ios/

然后,我照常做。

git add .
git commit -am "First commit"
git push -u origin master

它已经装好了。

团队成员做git clone时 然后做了npm install

它没有加载任何东西!

package.json

{
  "name": "gmxWorldWide",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.4.1",
    "react-native": "0.56.0",
    "watchman": "^1.0.0"
  },
  "devDependencies": {
    "babel-jest": "23.4.0",
    "babel-preset-react-native": "5",
    "jest": "23.4.1",
    "react-test-renderer": "16.4.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

它没有安装任何东西。

我来自php背景,其中composer.json将在团队中复制,而composer install会成功。

有什么不同?启用npm install可以做什么?

编辑:

该代码是使用react-native init命令创建的

2 个答案:

答案 0 :(得分:1)

由于您将node_modules目录提交到git,因此在克隆应用程序时已加载了所需的模块。您必须从存储库中忽略node_modules。但是我在您的{{1}中看到了}它已被评论

.gitignore

将其更新为关注(取消评论)

# node.js
# node_modules/ npm-debug.log yarn-error.log

创建React Native应用程序的最佳方法是使用# node.js node_modules/ npm-debug.log yarn-error.log 。在此处https://facebook.github.io/react-native/docs/getting-started.html

了解更多信息

编辑: 您必须提交create-react-native-app文件,以确保您的所有团队使用相同的库版本。但是无论如何,这可能会增加一些麻烦的麻烦,每个package-lock.json都可能会将现有软件包更新为所需的版本。 npm install文件中提到。

有关package-lock.json的更多详细信息,这里:https://docs.npmjs.com/files/package-lock.json

第二编辑: 如果要锁定版本,请使用package.json文件进行操作,只需使用确切的软件包版本而不是使用版本范围(<=,〜,^)

package.json上的固定版本

package.json

答案 1 :(得分:1)

结果是React带有内置命令。

我们执行了:

react-native eject

,并使用项目中的本机代码重新创建了Android和iOS文件夹。

拉动之后:

npm install
react-native eject
相关问题