Cordova Build - ignore files
Asked Answered
E

6

11

When compiling a cordova application every single file in my /www folder gets copied to the assets/www folder(android) but I'd like to customize what files are copied. I use several pseudo languages like CoffeeScript, Jade or Stylus which are auto-compiled by my IDE and they shouldn't be shipped into the final application.

Emblazonment answered 15/1, 2014 at 16:27 Comment(0)
M
7

With the help of this article, I found that you can create/edit the platform/android/ant.properties, and add the following line to it:

aapt.ignore.assets=!*.map:!thumbs.db:!.git:.*:*~

With this line, any file or directory that matches one of these patterns will not be included in the .apk file:

  • *.map
  • thumbs.db
  • .git
  • .*
  • *~

I found that editing the platforms/android/build.xml won't work because it's overwritten each time the build is invoked; also, creating a build.xml file in the root of the project didn't work.

The rules for this property are the following, taken from $ANDROID_HOME/tools/ant/build.xml:

<!-- 'aapt.ignore.assets' is the list of file patterns to ignore under /res and /assets.
         Default is "!.svn:!.git:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~"

         Overall patterns syntax is:
           [!][<dir>|<file>][*suffix-match|prefix-match*|full-match]:more:patterns...

         - The first character flag ! avoids printing a warning.
         - Pattern can have the flag "<dir>" to match only directories
           or "<file>" to match only files. Default is to match both.
         - Match is not case-sensitive.
    -->
    <property name="aapt.ignore.assets" value="" />
Mittel answered 2/12, 2014 at 19:8 Comment(4)
Is there any possibility to ignore eg. text.txt only in one certain subdirectory of /res or /assets?Towns
This is Android specific, and I am downvoting this answer because of that.Ariana
@amn ..and the question mentions/is tagged with Android.Mittel
Oh. Didn't see that. Checked the question for "android" but didn't look at the tags. And now I can't remove my downvote :( Sorry about that!Ariana
I
3

Hidden (.*) folder & files will be ignored by default

All hidden files and folders will be ignored while build for example .git/ & .gitignore

To hide : Rename the folder by a . (dot) prepended to the folder/file name.

Use Terminal in Linux/Mac to rename the folder.

mv dev .dev

Use cmd in Windows

ren dev .dev
Increate answered 30/12, 2014 at 4:17 Comment(0)
P
3

I highly recommend cordova-plugin-exclude-files. You simply specify files to exclude as pattern attributes of exclude-files tags in your config.xml file.

For example, to exclude all .scss files:

<exclude-files pattern="**/*.scss" />

And to exclude all files with the string "ios-only" on the Android platform only:

<platform name="android"> <exclude-files pattern="ios-only" /> </platform>

Polarize answered 10/5, 2018 at 13:0 Comment(2)
How would you exclude the .git folder? I've tried with several patterns without luck... I've tried **/.git, .git, **/git and othersHankins
@Hankins the build should not be picking up hidden files and folders. But what's more is that (if www is your build output) then you shouldn't have to version control it at all. But if you absolutely must - perhaps this link is helpful? github.com/markmarijnissen/cordova-app-loader/issues/28Polarize
T
2

I do not know any way how to filter files for cordova, but I can describe you approach that we use in our projects.

We are using gruntjs with phonegap plugin. We configure it to use prebuilt folder (which contains only necessary files and folders) and it:

  • creates cordova/phonegap project
  • adds plugins,platforms
  • builds native applicaiton
  • launches native application on emulator

Main thing in this approach is that cordova/phonegap project (directory with .cordova, platforms and www folders) is just a build artefact.

Here is relevant part of our Gruntfile.js as an example:

  phonegap : {
     config : {
        root : './out/dist',
        config : {
           template : './config.tpl.xml',
           data: {
              id: pkg.id,
              version: pkg.version,
              name: pkg.name,
              author : pkg.author
           }
        },
        path : 'out/phonegap',
        plugins : [
           // PHONEGAP OFFICIAL PLUGINS
           'org.apache.cordova.globalization',
           'org.apache.cordova.network-information',
           'org.apache.cordova.splashscreen',

           //THIRD-PARTY PLUGINS
           'de.appplant.cordova.plugin.local-notification'
        ],
        platforms : [
           'android'
        ],
        maxBuffer : 200, // You may need to raise this for iOS.
        verbose : false,
        releases : 'out/releases',
        releaseName : function() {
           return pkg.name + '-v' + pkg.version;
        },

        // Android-only integer version to increase with each release.
        // See http://developer.android.com/tools/publishing/versioning.html
        versionCode : function() {
           return 1;
        }
     }
  }

Note, out/dist is generated by previous build step and contains concatenated and minified version of code.

Thurmond answered 15/1, 2014 at 17:48 Comment(0)
T
1

I've created a custom script to ignore files/folders which works not just for android:

Add this to your config.xml:

<ignore entries="lang,foo/bar,ignore/asdf.html" />

And you need two more files located in hooks/before_build and hooks/after_build folders.

Tuggle answered 29/2, 2016 at 13:43 Comment(0)
I
0

This is what I'm doing. I've moved the src files for the app that was in www folder to another folder created in root - web-app. Next, the following script was added in package.json :

enter image description here

This surely needs to be refined, but am working with it as makeshift arrangement.

Good Luck...

Ingvar answered 22/12, 2018 at 8:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.