My project structure is the following:
MyApp
- hooks
- platforms
- android
- ios
- www
- js / css / templates..
- lib (including all bower components)
Right now, the www/lib
directory is taking up 21,8 Mb. (I have a large set of bower components added to my project.)
When building each project, the entire www
folder is copied to the platform/android
(for instance) folder for build, including of course www/lib
.
This leads to a very big build, as lots of files included into bower components are useless for production.
Manually managing all bower dependencies is clearly not an option. So how do you guys manage to clean your project platform directory for build?
I was thinking about creating a hook for that but before writing lines of code in a language that i do not know (nodeJS), I was hoping for your return and advises.
According to Cordova workflow you can add a hook script that removes unnecessary files. A detailed example of a cleanup script can be found here: https://blog.nraboy.com/2015/01/hooks-apache-cordova-mobile-applications/
But to give a quick step by step summary:
Add to the after_prepare hook folder (/hooks/after_prepare) a script (01_junk_cleanup.js - 01 to be run first, the rest whatever you want) and in the file specify the files and folders you want to delete. For example, here is how you can delete a test folder and relevant files just change to you lib directory and to the files there. Note that this example is a bit different from the example in the link i gave earlier so you might want to take a look there as well.
01_junk_cleanup.js:
Aside to above, A bit more obvious but I feel worth mentioning anyhow, After having the www/lib bloat as well I always try to keep the folder lean and add only libraries required for deployment, the other dev. dependencies such as jasmine I either hold in the 'node_modules' folder or 'bower_components' as I only install today through them.
Hope this helps, Good luck
This is an improvement over this answer. I've applied it to my own project.
bower_components
folder to the project root, outside thewww
folder.index.html
to_index.html
. We will later make sure that Gulp automatically generatesindex.html
.Edit your
_index.html
so that it looks something like this:<!-- build:js dist/js/vendor.js -->
<script src="../bower_components/ionic/release/js/ionic.bundle.min.js"></script>
<script src="../bower_components/ngstorage/ngStorage.min.js"></script>
<script src="../bower_components/ngCordova/dist/ng-cordova.min.js"></script>
<!-- endbuild -->
Configure your
gulp watch
task to build newindex.html
file in thewww
folder with the concatenated files.When that task runs, your
index.html
file will contain just this:ionic.project
file so that it looks like the following. This will make sure thatgulp watch
is run beforeionic serve
.I think the best approach would be to do this:
<build:js>
and<build:css>
sectionsThis will keep your /www folder tidy and only containing the files you need in your cordova build.
With Bower you need to use npm preen to remove unnecessary files
See my example using Gulp with Ionic Framework: https://github.com/jdnichollsc/Ionic-Starter-Template
Basically you can set your bower.json file to indicate the path which files you need, for example:
Regards, Nicholls