2
votes

I know that this question has been asked earlier here but the answer to the question is not telling about any way in which this can be solved, so I am asking a new question. I need any workaround that can be used to solve the problem. I do not want to take out all the files to a separate directory because I want visual studio to manage my project. And I am not very much agreeing to the idea of having all the application code outside the actual project in a separate project.

Background I have following directory structure for my Hybrid app project:


Project
------------app
------------dist (created by gulp utility using files from app directory)
------------images
------------merges
------------node_modules
------------index.html
------------bower_components

We are using gulp to concatenate all our js files and place it in dist directory as a single file.

Problem The problem that we are facing while compiling our app is that the plugin tries to copy even the node modules as well as the app folder to the build which we do not want. Is there any way to specify what all files we want cordova to copy or say ignore during the platform specific build for all platforms. Like here I only want that files from only dist directory get copied we do not want anything from app directory to be copied during build.

4

4 Answers

6
votes

A fast (but not super clean) solution is to tell the vs-mda plugin to ignore your additionnal folders and files. This can be done in the 'util.getDefaultFileNameEndingExclusions()' function in '%APPDATA%\npm\node_modules\vs-mda\lib\util.js'

Sample :

return [settings.projectSourceDir + '/bin',
        settings.projectSourceDir + '/bld',
        settings.projectSourceDir + '/merges',
        settings.projectSourceDir + '/plugins',
        settings.projectSourceDir + '/res',
        settings.projectSourceDir + '/test',
        settings.projectSourceDir + '/tests',
        settings.projectSourceDir + '/node_modules', // Ignore node_modules
        'gruntfile.js', 'package.json', '.vspscc',   // Ignore other files in root
        '.jsproj', '.jsproj.user'];

and enjoy the lightweigth package ! (11Mo -> 4Mo for iOS for me)

More info on integrating grunt/gulp with visual in this answer from creal : Multi-device hybrid apps: How to do combine, minify and obfuscate in release and distribution build process?

3
votes

I wrote this plugin that MAY solve this problem -> Here is the Code

Excludes directories recursively by default now. See the README.

1
votes

Hi i've posted a similar question here ( How to merge or override the build.xml for Android in phonegap / Cordova )

I know you don't want to move folders but I didn't found any solution but moving the "node_modules" in the parent folder, you have done a good choice by choosing Gulp, because I know that Gulp can find the modules in parents folders (in my own project I used Grunt which can't do this on his own...)

I think this is the only one solution.

1
votes

This isn't an ideal solution but, for want of a better option, it seems to work:

  1. Create an empty project (as described here https://stackoverflow.com/a/21695488/2117077). Put all of your source (html, css, js, etc) into it, so it becomes your new 'app' folder.
  2. Install your node and bower modules into this project.
  3. In this new project, configure gulp to output to the dist folder in your cordova project.
  4. Build your cordova project, which should now contain only your concatenated files.

I used grunt to test this, but I think it should be replicable with gulp. I also, as a convenience, added an msbuild target to the cordova project, so that grunt is called on build.

There are still some other files that this doesn't solve (for me, vspscc files), so a substantive solution (some sort of ignore file?) is still needed.