Cordova Build - ignore files

前端 未结 6 695
孤街浪徒
孤街浪徒 2021-02-08 10:58

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

相关标签:
6条回答
  • 2021-02-08 11:31

    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 :

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

    Good Luck...

    0 讨论(0)
  • 2021-02-08 11:38

    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>

    0 讨论(0)
  • 2021-02-08 11:40

    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.

    0 讨论(0)
  • 2021-02-08 11:44

    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="" />
    
    0 讨论(0)
  • 2021-02-08 11:46

    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.

    To Rename a folder with .(dot) at start you may need CLI

    Use Terminal in Linux/Mac to rename the folder.

    mv dev .dev
    

    Use cmd in Windows

    ren dev .dev
    
    0 讨论(0)
  • 2021-02-08 11:48

    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.

    0 讨论(0)
提交回复
热议问题