[英]Cordova Build - ignore files
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. 编译cordova应用程序时,我
/www
文件夹中的每个文件都被复制到assets/www
文件夹(android),但我想自定义要复制的文件。 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. 我使用了几种伪语言,如CoffeeScript,Jade或Stylus,它们由我的IDE自动编译,不应该发送到最终的应用程序中。
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: 在本文的帮助下,我发现您可以创建/编辑
platform/android/ant.properties
,并platform/android/ant.properties
添加以下行:
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: 使用此行,匹配其中一个模式的任何文件或目录都不会包含在.apk文件中:
*.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; 我发现编辑
platforms/android/build.xml
行不通的,因为每次调用构建时它都会被覆盖; also, creating a build.xml
file in the root of the project didn't work. 另外,在项目的根目录中创建
build.xml
文件不起作用。
The rules for this property are the following, taken from $ANDROID_HOME/tools/ant/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="" />
All hidden files and folders will be ignored while build for example .git/
& .gitignore
构建时将忽略所有隐藏文件和文件夹,例如
.git/
.gitignore
To hide : Rename the folder by a .
隐藏:用a重命名文件夹
.
(dot) prepended to the folder/file name. (点)前置于文件夹/文件名。
To Rename a folder with .(dot) at start you may need CLI 要在开始时使用。(点)重命名文件夹,您可能需要CLI
Use Terminal in Linux/Mac to rename the folder. 在Linux / Mac中使用终端重命名该文件夹。
mv dev .dev
Use cmd in Windows 在Windows中使用cmd
ren dev .dev
I do not know any way how to filter files for cordova, but I can describe you approach that we use in our projects. 我不知道如何过滤cordova的文件,但我可以描述一下我们在项目中使用的方法。
We are using gruntjs with phonegap plugin. 我们使用gruntjs与PhoneGap的插件。 We configure it to use prebuilt folder (which contains only necessary files and folders) and it:
我们将其配置为使用预建文件夹(仅包含必要的文件和文件夹)并且:
Main thing in this approach is that cordova/phonegap project (directory with .cordova, platforms and www folders) is just a build artefact. 这种方法的主要内容是cordova / phonegap项目(带有.cordova,平台和www文件夹的目录)只是一个构建工件。
Here is relevant part of our Gruntfile.js as an example: 以下是我们的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;
}
}
}
Note, out/dist is generated by previous build step and contains concatenated and minified version of code. 注意,out / dist由先前的构建步骤生成,并包含连接和缩小版本的代码。
I've created a custom script to ignore files/folders which works not just for android: 我创建了一个自定义脚本来忽略不仅适用于android的文件/文件夹:
Add this to your config.xml : 将其添加到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. 而且你还需要两个位于hooks / before_build和hooks / after_build文件夹中的文件。
I highly recommend cordova-plugin-exclude-files . 我强烈推荐cordova-plugin-exclude-files 。 You simply specify files to exclude as
pattern
attributes of exclude-files
tags in your config.xml
file. 您只需指定要排除的文件作为
config.xml
文件中exclude-files
标记的pattern
属性。
For example, to exclude all .scss
files: 例如,要排除所有
.scss
文件:
<exclude-files pattern="**/*.scss" />
And to exclude all files with the string "ios-only" on the Android platform only: 并且仅在Android平台上排除字符串“仅限ios”的所有文件:
<platform name="android"> <exclude-files pattern="ios-only" /> </platform>
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
. 我已将
www folder
的应用程序的src
文件移动到在root- web-app
创建的另一个文件夹中。 Next, the following script
was added in package.json
: 接下来,在
package.json
中添加了以下script
:
This surely needs to be refined, but am working with it as makeshift arrangement. 这肯定需要改进,但我正在使用它作为临时安排。
Good Luck... 祝好运...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.