Cordova Build - 忽略文件

时间:2014-01-15 16:27:51

标签: android cordova cordova-3

编译cordova应用程序时,/www文件夹中的每个文件都会被复制到assets/www文件夹(android),但我想自定义要复制的文件。我使用了几种伪语言,如CoffeeScript,Jade或Stylus,它们由我的IDE自动编译,不应该发送到最终的应用程序中。

6 个答案:

答案 0 :(得分:6)

this article的帮助下,我发现您可以创建/编辑platform/android/ant.properties,并在其中添加以下行:

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

使用此行,匹配其中一种模式的文件目录将不会包含在.apk文件中:

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

我发现编辑platforms/android/build.xml 无法正常工作,因为每次调用构建时都会覆盖它;另外,在项目的根目录中创建build.xml文件并不起作用。

此属性的规则如下,取自$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="" />

答案 1 :(得分:3)

隐藏(。*)文件夹&amp;默认情况下将忽略文件

构建时会忽略所有隐藏文件和文件夹,例如.git/&amp; .gitignore

隐藏:通过文件夹/文件名前面的.(点)重命名文件夹。

要在开始时使用。(点)重命名文件夹,您可能需要CLI

在Linux / Mac中使用终端重命名文件夹。

mv dev .dev

在Windows中使用cmd

ren dev .dev

答案 2 :(得分:2)

我不知道如何过滤cordova的文件,但我可以描述一下我们在项目中使用的方法。

我们正在使用gruntjsphonegap插件。我们将其配置为使用预建文件夹(仅包含必要的文件和文件夹)和它:

  • 创建cordova / phonegap项目
  • 添加了插件,平台
  • 构建本机应用程序
  • 在模拟器上启动本机应用程序

这种方法的主要内容是cordova / phonegap项目(带有.cordova,平台和www文件夹的目录)只是一个构建工件。

以下是 Gruntfile.js 的相关部分作为示例:

  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;
        }
     }
  }

注意,out / dist是由上一个构建步骤生成的,包含连接和缩小版本的代码。

答案 3 :(得分:1)

我创建了一个自定义脚本来忽略不仅适用于android的文件/文件夹:

将此添加到 config.xml

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

您需要two more files位于hooks / before_build hooks / after_build 文件夹中。

答案 4 :(得分:1)

我强烈推荐cordova-plugin-exclude-files。您只需指定要在exclude-files文件中排除config.xml.scss标记属性的文件。

例如,要排除所有<exclude-files pattern="**/*.scss" />个文件:

  

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

并且仅在Android平台上排除字符串“仅限ios”的所有文件:

  

db_file_names = ['f1', 'f2'] # list of database files def make_report(filename): # read the database and prepare some report object return report_object

答案 5 :(得分:0)

这就是我在做什么。我已经将src中应用程序的www folder文件移到了在根目录web-app中创建的另一个文件夹。接下来,在script中添加了以下package.json

enter image description here

这肯定需要改进,但是正在作为临时安排使用。

祝你好运...

相关问题