Cordova 5.0.0: 我应该提交哪些文件给 git?

我使用 Cordova 5.0.0,我有以下项目结构:

MyProject
- hooks
- platforms
- plugins
- resources
- www
- config.xml

我现在的问题是: 这些文件夹中哪些可以省略?我这么问是因为我在三个不同的平台上工作。我为 android 开发 linux,为 windows phone 开发 windows,为 ios 开发 mac。如果我提交整个项目,我总是会得到不支持的平台的警告和错误。

我想要的是一个简约的 git 存储库。

例如,插件就是一个问题。当我从存储库中删除插件文件夹时,我必须在每个开发平台上手动添加它们。

另一个问题是资源文件夹。我自动生成图标和启动画面使用离子。当我现在尝试在 ios 上构建这个项目时,它正在抱怨 Android 的图像。

那么我需要什么,我能省略什么呢?

34252 次浏览

It depends on the platforms.

You can use this example of .gitignore and customize according to your needs.

# Mac
.DS_Store


# iOS
platforms/ios/build/
platforms/ios/www/
platforms/ios/cordova/console.log
*.xcuserdatad


# android
platforms/android/assets/www
platforms/android/bin
platforms/android/gen
platforms/android/local.properties
platforms/android/ant-build
platforms/android/ant-gen
platforms/android/CordovaLib/ant-build
platforms/android/CordovaLib/ant-gen
platforms/android/CordovaLib/bin
platforms/android/CordovaLib/gen
platforms/android/CordovaLib/local.properties


# wp8
platforms/wp8/bin
platforms/wp8/obj
platforms/wp8/www
platforms/wp8/.staging
platforms/wp8/*.suo
platforms/wp8/*.csproj.user


# res
resources/signing

You can ignore the platforms and plugins directories as long as you haven't added any custom code in them.

When adding plugins and platforms add --save to the command. e.g.

cordova platform add ios@3.8.0 --save

or

cordova plugin add cordova-plugin-device --save

This will save a record of the plugins and platforms you use to your config.xml file. When you run cordova prepare or cordova build all of your plugins and platforms listed in config.xml will be installed if they haven't been already.

You can also specify a platform in prepare and build. So if you are on your Mac, you can check out the git repository and run cordova prepare ios to install just the ios platform and plugins.

I add to the Niko list :

# IntelliJ IDEA files
*.iml
.idea


#windows
Thumbs.db
Desktop.ini

and

*.sw[mnpcod]
*.log
*.tmp
*.tmp.*
log.txt

You can save platform and plugin afterwards by using following commands.

platform mass saving

$ cordova platform save

Plugins mass saving

$ cordova plugin save

Kindly note that there is no -- in above commands

One More thing, after fetching repo on another machine you just run following command to generate and fetch plugins and platforms automatically

$ cordova prepare

For more reference visit the links below. https://cordova.apache.org/docs/en/latest/platform_plugin_versioning_ref/#mass-saving-platforms-on-an-existing-project

Cordova Tip: Always refer to official docs before before anything else to get the right solution.

I followed these steps:

  • create cordova project

  • add platforms

  • add plugins

Before build project, I commit and push generated files. After I build project and check for new files generated. I got these to add in .gitignore:

/platforms/android/gradlew.bat

/platforms/android/build

/platforms/android/gradle

/platforms/android/libs

/platforms/android/gradlew.bat

/platforms/android/CordovaLib/build

/platforms/android/.gradle

I don't know the answer, but I've found something that might help. This pull request was approved.

Here's the file :

# Mac
.DS_Store


# Node
npm-debug.log
/node_modules


# Cordova
/platforms
/plugins


# res
resources/signing

Most of the other answers are 2/3 years old.

2019 Update:

# remove extension less files
*
!/**/
!*.*


# intermediate files
node_modules/
build/
obj/
Debug/
bin/
package-lock.json
.vs
.gradle
.idea
*.exe


# res
**/resources/signing


# project specific
**/dist/
**/all.min.js


# ========== Cordova - platforms
# android
# platforms/android/app/src/main/assets
# platforms/android/app/src/main/AndroidManifest.xml
# platforms/android/app/src/main/res/drawable-*
# platforms/android/app/src/main/res/mipmap-*
# platforms/android/app/src/main/res/xml/config.xml
# browser
# platforms/browser/app/src/main/assets
# platforms/browser/config.xml
# platforms/browser/www
#
# ========== Cordova - plugins - remove all except json & xml
# plugins/**/.DS_Store
# plugins/**/*.cs
# plugins/**/*.h
# plugins/**/*.java
# plugins/**/*.js
# plugins/**/*.m
# plugins/**/*.map
# plugins/**/*.md
# plugins/**/*.modulemap
# plugins/**/*.ts
# plugins/**/LICENSE
# plugins/**/NOTICE
# plugins/**/*.gradle
# plugins/**/tests/

As you can see I commented most of the lines ( all lines starting with # ). This is because I ran into issues with plugin version changes, and decided to know what is happening with plugin updates. Essentially all platform & plugin files are included in commit, now my life is peaceful.

2019:
I stated with this.

After developing & publishing the app, it became below:
(If you deviate from below, comment below, we can learn from each other)

# remove extension less files
*
!/**/
!*.*


# intermediate files
node_modules/
build/
obj/
Debug/
bin/
package-lock.json
.vs
.gradle
.idea
*.exe


# Cordova - platforms
platforms


# Cordova - plugins - remove all except json & xml
plugins/**/.DS_Store
plugins/**/*.cs
plugins/**/*.h
plugins/**/*.java
plugins/**/*.js
plugins/**/*.m
plugins/**/*.map
plugins/**/*.md
plugins/**/*.modulemap
plugins/**/*.ts
plugins/**/LICENSE
plugins/**/NOTICE
plugins/**/*.gradle
plugins/**/tests/


# res
**/resources/signing


# project specific
**/dist/
**/all.min.js

2021 Update - using Android platform:

# Node Package Manager
node_modules/
npm-debug.log


# Gradle
.gradle


# IntelliJ IDEA
**/.idea/**/*
*.iml
coverage/
.nyc_output/


# Other generated files & folders
bin/*
build
gen


# Cordova Plugins: remove all except json & xml
plugins/*
!plugins/**/*.json
!plugins/**/*.xml


# Cordova Platform: Android
platforms/android/assets/www
platforms/android/bin
platforms/android/gen
platforms/android/local.properties
platforms/android/ant-build
platforms/android/ant-gen
platforms/android/CordovaLib
platforms/android/cordova/
platforms/android/app/gradle
platforms/android/app/src/main/java
platforms/android/app/release
platforms/android/app/gradlew
platforms/android/**/*.bat
platforms/android/app/src/main/assets/www
platforms/android/platform_www


# Cordova www folder
# Files will be built into this folder
www/**/*
!www/.gitkeep

With my setup I have a build script which bundles and minifies the content of the www folder so I ignored it as well.