cordova的多个config.xml文件

时间:2021-07-04 07:26:10

I am building a Cordova application that I am allowing different clients to brand. I was wondering if there was a way to have a default config.xml, and then have second file that overrides the default with the branded values. There are quite a few values I need to override, however some of the more obvious are :

我正在构建一个Cordova应用程序,我允许不同的客户品牌。我想知道是否有一种方法可以使用默认的config.xml,然后让第二个文件使用品牌值覆盖默认值。我需要覆盖很多值,但更明显的一些是:

  • The id and version attributes of widget
  • 小部件的id和version属性
  • name
  • 名称
  • description
  • 描述
  • author
  • 作者
  • icon (how would I override multiple of the same tag?)
  • 图标(如何覆盖同一个标签的多个?)
  • splash

If there is not a Cordova way of doing this, is there a linux tool that I could use for this purpose that would output my single config.xml file?

如果没有Cordova方式这样做,是否有一个我可以用于此目的的linux工具将输出我的单个config.xml文件?

1 个解决方案

#1


1  

The best way to do this is to actually create a separate project for each instance of your application.

实现此目的的最佳方法是为应用程序的每个实例创建一个单独的项目。

Here is how I would solve this:

以下是我将如何解决这个问题:

1.Create a template for the config.xml file.

1.为config.xml文件创建模板。

2.Create a www folder (containing the files of your application) in the same directory where you will create the project_folders for each instance of the application.

2.在同一目录中创建一个www文件夹(包含应用程序的文件),您将在该目录中为每个应用程序实例创建project_folders。

3.Create new instances of the application cordova create...

3.创建应用程序cordova的新实例创建...

4.In each instance copy the template of config.xml over the existing one and modify for the specific instance.

4.在每个实例中,将config.xml的模板复制到现有模板上,并针对特定实例进行修改。

5.Either copy the www folder from the directory above the project_root into it, or remove the www folder from the project_root and create a symlink to the www folder in the directory above the project_root.

5.将www文件夹从project_root上方的目录复制到其中,或者从project_root中删除www文件夹,并在project_root上方的目录中创建一个符号链接到www文件夹。

Now you have separate instances of your application, all sharing the same www contents but with custom config.xml files.

现在您有了应用程序的单独实例,所有实例共享相同的www内容,但使用自定义config.xml文件。

Example Directory Structure:

示例目录结构:

App_Name
  \config.xml
  \www
  \{project_instance_1}
    \{config replaced}
    \www -> ../www
  \{project_instance_2}
    \{config replaced}
    \www -> ../www

#1


1  

The best way to do this is to actually create a separate project for each instance of your application.

实现此目的的最佳方法是为应用程序的每个实例创建一个单独的项目。

Here is how I would solve this:

以下是我将如何解决这个问题:

1.Create a template for the config.xml file.

1.为config.xml文件创建模板。

2.Create a www folder (containing the files of your application) in the same directory where you will create the project_folders for each instance of the application.

2.在同一目录中创建一个www文件夹(包含应用程序的文件),您将在该目录中为每个应用程序实例创建project_folders。

3.Create new instances of the application cordova create...

3.创建应用程序cordova的新实例创建...

4.In each instance copy the template of config.xml over the existing one and modify for the specific instance.

4.在每个实例中,将config.xml的模板复制到现有模板上,并针对特定实例进行修改。

5.Either copy the www folder from the directory above the project_root into it, or remove the www folder from the project_root and create a symlink to the www folder in the directory above the project_root.

5.将www文件夹从project_root上方的目录复制到其中,或者从project_root中删除www文件夹,并在project_root上方的目录中创建一个符号链接到www文件夹。

Now you have separate instances of your application, all sharing the same www contents but with custom config.xml files.

现在您有了应用程序的单独实例,所有实例共享相同的www内容,但使用自定义config.xml文件。

Example Directory Structure:

示例目录结构:

App_Name
  \config.xml
  \www
  \{project_instance_1}
    \{config replaced}
    \www -> ../www
  \{project_instance_2}
    \{config replaced}
    \www -> ../www