科尔多瓦插件的package.json与config.xml [英] package.json vs config.xml for cordova plugins

查看:125
本文介绍了科尔多瓦插件的package.json与config.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用cordova@5.4.0& ionic-cli@1.7.8,我面临2种可能性:

On a project using cordova@5.4.0 & ionic-cli@1.7.8, I face 2 possibilities:

cordova create dummy-project && cd dummy-project
cordova platform add browser --save
cordova plugin add cordova-plugin-device --save

## If forgot to add `--save` option, manually update config.xml
#cordova platform save
#cordova plugin save

# reset platforms & plugins, like we just checked out the repository
rm -rf platforms plugins

# `cordova prepare` automatically setup platforms & plugins
# dependencies via config.xml
cordova prepare

专业人士

  • 平台和插件属于 Cordova领域,因此使用cordova似乎很直观
  • 平台和插件版本保存在config.xml中,如下所示:

  • Platforms and plugins belong to the Cordova realm, so it seems intuitive to use cordova
  • Platforms and plugins versions are saved in config.xml like below:

<plugin name="cordova-plugin-device" spec="~1.0.1" />
<engine name="browser" spec="~4.0.0" />

  • 签出仓库的多个开发人员将获得相同的依赖项

  • Multiple developers who checkouts the repo will get the same dependencies

    缺点

    • 另一个配置文件config.xml会使项目的根目录杂乱无章
    • plugins/fetch.jsonplatforms/platforms.json中的重复信息?
    • 必须显式添加--save选项
    • Yet another config file config.xml which clutters the project's root directory
    • Duplicate infos in plugins/fetch.json and platforms/platforms.json ?
    • Must explicitly add --save option
    ionic start dummy-project blank && cd dummy-project
    ionic platform add browser
    ionic plugin add cordova-plugin-device
    
    # reset platforms & plugins, like we just checked out the repository
    rm -rf platforms plugins
    
    # fetch platforms & plugins dependencies via package.json
    ionic state restore
    

    专业人士

    • 项目的依赖项通过以下自定义键合并为package.json:
      • cordovaPlugins
      • cordovaPlatforms
      • Pros

        • Project's dependencies consolidated into package.json with the following custom keys:
          • cordovaPlugins
          • cordovaPlatforms
            • package.json中没有插件或平台的版本固定(对我而言这是一个巨大的障碍)
            • 为什么不把cordova插件&平台进入dependencies,因为它们仍然是NPM软件包? ionic可以使node_modules& {plugins,platforms}/
            • No version pinning for plugins nor platforms in package.json (that's a huge blocker for me)
            • Why not put cordova plugins & platforms into dependencies since they are NPM packages anyway ? ionic could symlink the dependancies between node_modules & {plugins,platforms}/

            是离子型&离子型吗?科尔多瓦开发商正在考虑统一/重构此事吗?

            Are the ionic & cordova developers considering a unification/refactorisation of this matter ?

            推荐答案

            第二次更新! 2017.05.

            它又变了-这次是在科尔多瓦一边. Cordova 7添加了对package.json

            It changes again - this time on Cordova side. Cordova 7 adds support for package.json!

            请参阅Cordova博客: http://cordova.apache .org/news/2017/05/04/cordova-7.html

            See on Cordova blog: http://cordova.apache.org/news/2017/05/04/cordova-7.html

            更新2016.05.

            由于缺少cordova中的功能,似乎创建了许多ionic命令,但是由于cordova赶上了并实现了许多新功能,离子维护人员正在考虑像ionic state那样转储它们的命令,以支持科尔多瓦提供的.

            It seems that many ionic commands were created due to lack of the features in cordova, but since cordova caught up and implemented many new features, the ionic maintainers are considering dumping their command like ionic state in favor of the ones provided by cordova.

            因此,似乎采用"cordova方式"可能更适合未来.

            So it seems that going the "cordova way" might be more future-proof.

            查看那些票证:

            • https://github.com/driftyco/ionic-cli/issues/904
            • https://github.com/driftyco/ionic-cli/issues/1324

            原始答案(2016.03.):

            我会说这是个人品味的问题.无论采用哪种解决方案,最好保持一致,然后始终使用cordova plugin add ...ionic plugin add,不要将两者混在一起.

            It's a matter of person taste I'd say. Whatever solution you go through, it's best to be consistent and then always use cordova plugin add ... or ionic plugin add and not mix the two.

            仅供参考,您可以使用ionic的解决方案来固定版本,但确实如此,您必须手动放置它,或者必须在安装过程中明确指定版本,例如ionic plugin add ionic-plugin-keyboard@1.0.8.与此相关的离子CLI肯定还有改进的空间.

            FYI you can have version pinning with ionic's solution, but true, you have to put it manually, or you have to specify the version explicitly during installation e.g. ionic plugin add ionic-plugin-keyboard@1.0.8. Definitely there's room for improvements in ionic CLI regarding that.

            例如,这是我们的package.json,其中包含固定的插件版本和平台版本,还固定了github SHA1:

            For example, this is our package.json with pinned plugin versions and platform versions as well, and also pinned github SHA1:

              "cordovaPlugins": [
                "ionic-plugin-keyboard@1.0.8",
                "cordova-plugin-inappbrowser@1.2.0",
                "phonegap-plugin-push@1.5.3",
                {
                  "locator": "https://github.com/Initsogar/cordova-webintent.git#3d12378de9f38be900761a0ad06ab697cf6d9add",
                  "id": "com.borismus.webintent"
                },
                {
                  "variables": {
                    "APP_ID": "123456789987654321",
                    "APP_NAME": "TEST"
                  },
                  "locator": "cordova-plugin-facebook4@1.6.3",
                  "id": "cordova-plugin-facebook4@1.6.3"
                }
              ],
              "cordovaPlatforms": [
                "android@4.1"
              ]
            

            然后,当您执行ionic state restore时,它将遵循列出的版本.

            Then when you do ionic state restore it will honor the versions listed.

            这篇关于科尔多瓦插件的package.json与config.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆