95

I use Cordova 5.0.0 and i have the following project structure:

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

My question now is: Which of these folders can I omit? I ask it because I work on three different platforms. I Develop on linux for android, windows for windows phone and on mac for ios. If I commit the whole project I always get warnings and error for the not supported platforms.

What I want is a minimalistic git repository.

One problem for example are the plugins. When I delete the plugin folder from the repository I have to add them on each of my developing platform manually.

Another problem is the resources folder. I automatically generate icons and splashscreens using ionic. When I now try to build the project on ios, it is complaining about the images for android.

So what do I need and what can I omit?

Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
Mulgard
  • 9,877
  • 34
  • 129
  • 232

8 Answers8

123

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.

Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
  • This works for existing plugins and platforms as well. Cordova will simply ignore re-installing, but will add the plugin to the config file. – rnevius May 26 '15 at 09:32
  • --save option only worked for me on platforms when platform hadn't been installed yet. – inki Sep 21 '15 at 22:03
  • Works on most (not all) already-installed plugins/platforms with `--save --force`. – Victor Sergienko Mar 09 '16 at 16:21
  • 4
    `cordova build` didn't restore platforms, but `cordova prepare` did on Cordova 6.0. – Victor Sergienko Mar 09 '16 at 16:44
  • 45
    If you forgot to `--save` platforms and plugins, just use `cordova platform save` and `cordova plugin save` (note no `--`), and it'll add the relevant lines to your `config.xml`. – jcaron Mar 29 '16 at 16:27
  • 1
    this worked fine for `platforms` but not for `plugins`. `cordova prepare` wouldn't work with at least `plugin.xml` and `src` . i gave up and just saved all of `plugins` to git. – Jayen Aug 04 '16 at 10:00
  • 7
    as of cordova 7.0.0 the default behaviour has been changed to saving. https://cordova.apache.org/news/2017/05/04/cordova-7.html – Kinjal Dixit Nov 24 '17 at 00:01
42

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
tomodian
  • 6,043
  • 4
  • 25
  • 29
Niko
  • 3,412
  • 26
  • 35
  • wouldn't it make sense to ignore also platforms/android/res? AFAIK/understnad, these are created during build process (from the res / resources folder in parent (project) directory). – Tomer Cagan Dec 20 '15 at 10:30
  • 4
    i was able to ignore `platforms/*/` with cordova 6.3.0 and do a `cordova prepare` on the other systems. – Jayen Aug 04 '16 at 10:02
  • This ignore file seems to include a lot of generated files, so it needs to be more narrow, I think. – Anders Lindén Jan 28 '17 at 13:52
  • 1
    Should it also include `node_modules`? I did. – Cameron A. Ellis Apr 04 '17 at 07:09
  • @CameronA.Ellis I do have `node_modules` either. Did you add it? Isn't there some way to download these node modules. – wviana May 23 '17 at 13:20
  • Niko's answer seems accurate... unfortunately. I'm on Cordova 8.0. If I ignore the entire platform directory, `cordova prepare` does _not_ re-download any of the required files, even though their documentation explicitly states that it will. I may end up removing/re-adding the platforms as a workaround: https://github.com/phonegap/phonegap-cli/issues/422 – Brandon Jul 19 '18 at 19:09
  • why not ignoring the full content of `platforms`? Just curious – João Pimentel Ferreira Jun 23 '19 at 20:22
19

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.

Hitesh Chavda
  • 772
  • 1
  • 9
  • 25
16

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
Nato Boram
  • 4,083
  • 6
  • 28
  • 58
4

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
Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140
  • 1
    You can simply do `plugins/*` then `!plugins/**/*.json` and `!plugins/**/*.xml` – Bernardo Dal Corno Mar 11 '19 at 19:05
  • also I've seen advised to not ignore package-lock – Bernardo Dal Corno Mar 11 '19 at 19:06
  • @z-khullah in the link provided, the "Optional to ignore plugin Git clones" is given because sometimes we change the code in them, so can't ignore all the files. Ideally, we can ignore, but there are online suggestions due to the issues in plugins, esp as a newbie to cordova it will help. the package-lock changes 10s or 20s of lines each time some plugin installatoin changes, so this is also something we dont want to code review, also by igoring lock file we din't have any issues till now, it gets generated from package.json. Hope that helps in giving our perspective. – Manohar Reddy Poreddy Mar 11 '19 at 22:48
  • Yes but the pattern does the same thing, only with fewer lines. As to package-lock, it helps debugging since it shows the exact node_modules structure, but yes, I think it is optional – Bernardo Dal Corno Mar 12 '19 at 02:47
  • Right, these 2 reasons could be. It's possible that the ! din't work for some reason, because I remember trying that. Also another reason I settled to this was, I was sure what I don't want (cs,java,etc), but I am sure what I want (json,xml -- but there could be others too, so I want to see them when they appear). Hmm.. may be on lock file, we saw several 100s of lines changing :-), so we ignored. – Manohar Reddy Poreddy Mar 12 '19 at 02:52
  • Good point, it's good to see what changes until certain. With time things get right. The "!" only works if before you added all explicitly with "*", otherwise it will ignore it.. really tricky! – Bernardo Dal Corno Mar 12 '19 at 02:56
  • Right. Right on the ! too, I spent 2/3 hour on it, the good point you noted, is the reason I recall now. Since I just started cordova development and want to be sure of everything I do :-), so that I can continue dev without any problems in the future I saw some others stopped game dev in middle as they were unable to maintain the quality). its kids game is already live in 2 days, and going good, I add features, multiple times, every day, hope all will go good in the future. I am sharing all details I find so it will help others. Me, back to work, goota eat. – Manohar Reddy Poreddy Mar 12 '19 at 04:08
  • you should not ignore `package-lock.json` – João Pimentel Ferreira Jun 23 '19 at 20:34
  • 1
    @ManoharReddyPoreddy https://stackoverflow.com/questions/44206782/do-i-commit-the-package-lock-json-file-created-by-npm-5#answer-44210813 – Adit Saxena Jul 01 '19 at 06:33
3

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

0

I add to the Niko list :

# IntelliJ IDEA files
*.iml
.idea

#windows
Thumbs.db
Desktop.ini

and

*.sw[mnpcod]
*.log
*.tmp
*.tmp.*
log.txt
Cédric Dromzée
  • 347
  • 4
  • 11
  • 2
    These are generally good to ignore, not specific to Cordova (like `.DS_Store` isn't in Niko's answer, either). – Jari Keinänen Oct 17 '16 at 13:18
  • These should probably be addressed in a [global gitignore](https://help.github.com/articles/ignoring-files/#create-a-global-gitignore), not a project-level one. – bdesham May 30 '18 at 19:50
0

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.

laszlo-horvath
  • 1,852
  • 2
  • 19
  • 20