【问题标题】:Recommended .gitignore for react-native推荐 .gitignore 用于 react-native
【发布时间】:2018-08-12 10:32:56
【问题描述】:

我正在尝试 react native 和 ejected 到一个完整的构建环境中。遗憾的是,eject-script 没有创建合理的.gitignore 文件。

对应用程序开发了解不多,我想知道我可以在这里.gitignore 哪些目录?

我猜:

  • android/build
  • android/app/build
  • android/.gradle/

这些都好吗,或者还有什么我应该.gitignore的目录?

【问题讨论】:

    标签: android react-native gradle


    【解决方案1】:

    下面是.gitignore 文件随react-native init 命令一起提供。你可以找到完整的文件here

    # 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/
    package-lock.json # include if you are using npm - don't use both yarn and npm
    npm-debug.log
    yarn-error.log
    yarn.lock # include if you are using yarn - don't use both npm and yarn
    
    # 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
    

    【讨论】:

    • package-lock.json 或 yarn.lock 应该被提交
    • 您绝对应该提交lock 文件之一。如果您使用的是npm,它应该是package-lock.json,如果您使用的是yarn,它应该是yarn.lock
    • 这是否也添加了 pod 文件?
    • 没有为我保留所有 Xcode 所需的项目设置...不确定问题的原因。
    • 上面的 git ignore 会忽略 android/app/build 吗?
    【解决方案2】:

    这是用于 react-native 项目的较新版本的 .gitignore https://github.com/facebook/react-native/blob/master/.gitignore

    添加包管理器锁定文件是可选的。您可以通过在下面的代码末尾添加 package-lock.json for npm 或 yarn.lock for yarn 来添加它们。

    # Xcode
    !**/*.xcodeproj
    !**/*.pbxproj
    !**/*.xcworkspacedata
    !**/*.xcsettings
    !**/*.xcscheme
    *.pbxuser
    !default.pbxuser
    *.mode1v3
    !default.mode1v3
    *.mode2v3
    !default.mode2v3
    *.perspectivev3
    !default.perspectivev3
    xcuserdata
    *.xccheckout
    *.moved-aside
    DerivedData
    *.hmap
    *.ipa
    *.xcuserstate
    project.xcworkspace
    
    # Gradle
    /build/
    /RNTester/android/app/build/
    /RNTester/android/app/gradle/
    /RNTester/android/app/gradlew
    /RNTester/android/app/gradlew.bat
    /ReactAndroid/build/
    
    # Buck
    .buckd
    buck-out
    /ReactAndroid/src/main/jni/prebuilt/lib/armeabi-v7a/
    /ReactAndroid/src/main/jni/prebuilt/lib/x86/
    /ReactAndroid/src/main/gen
    
    # Watchman
    .watchmanconfig
    
    # Android
    .idea
    .gradle
    local.properties
    *.iml
    /android/
    
    # Node
    node_modules
    *.log
    .nvm
    /bots/node_modules/
    package-lock.json
    
    # OS X
    .DS_Store
    
    # Test generated files
    /ReactAndroid/src/androidTest/assets/AndroidTestBundle.js
    *.js.meta
    
    /coverage
    /third-party
    
    # Root dir shouldn't have Xcode project
    /*.xcodeproj
    
    # ReactCommon subdir shouldn't have Xcode project
    /ReactCommon/**/*.xcodeproj
    RNTester/build
    
    # Libs that shouldn't have Xcode project
    /Libraries/FBLazyVector/**/*.xcodeproj
    /Libraries/FBReactNativeSpec/**/*.xcodeproj
    /Libraries/RCTRequired/**/*.xcodeproj
    /React/CoreModules/**/*.xcodeproj
    /packages/react-native-codegen/**/*.xcodeproj
    
    # CocoaPods
    /template/ios/Pods/
    /template/ios/Podfile.lock
    /RNTester/Gemfile.lock
    
    # Ignore RNTester specific Pods, but keep the __offline_mirrors__ here.
    RNTester/Pods/*
    !RNTester/Pods/__offline_mirrors
    
    # react-native-codegen
    /ReactCommon/fabric/components/rncore/
    /schema-rncore.json
    

    【讨论】:

    • 这是实际的 react-native 存储库 gitignore。请参阅已接受答案的链接以获取 React Native 项目的示例模板。
    【解决方案3】:

    这是我正在使用的。

    内容应该在ios和android环境(签名,配置文件)init之后保存在.gitignore中,

    然后需要使用 git rm -f ---cached (file path) 删除自动生成的文件,如 (index.android.bundle,main.jsbundle),然后提交,然后创建一个新的。

    那是因为不需要提交自动生成的文件。

    node_modules/**/*
    .expo/*
    npm-debug.*
    *.jks
    *.p8
    *.p12
    *.key
    *.mobileprovision
    *.orig.*
    web-build/
    package-lock.json
    # macOS
    .DS_Store
    ios/
    ios/*
    ios/main.jsbundle
    ios/**/*
    android/
    android/*
    android/**/*
    
    .vs/
    *.log
    
    # 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
    *.hprof
    
    # node.js
    #
    node_modules/
    npm-debug.log
    yarn-error.log
    
    # BUCK
    buck-out/
    \.buckd/
    *.keystore
    !debug.keystore
    
    # Bundle artifacts
    *.jsbundle
    
    # CocoaPods
    /ios/Pods/
    
    # Expo
    .expo/
    web-build/
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-14
      • 2022-01-03
      • 1970-01-01
      • 2019-12-09
      • 1970-01-01
      • 1970-01-01
      • 2020-11-09
      • 2017-12-05
      相关资源
      最近更新 更多