简体   繁体   English

Cordova:排除插件和平台

[英]Cordova: Exclude plugins and platforms

I would like to not include the platforms and plugins in my git repository for my cordova project.我不想在我的cordova 项目的git 存储库中包含平台和插件。 Instead, I only include platforms/platforms.json and plugins/fetch.json .相反,我只包含platforms/platforms.jsonplugins/fetch.json My .gitignore looks like this我的.gitignore看起来像这样

platforms/**
!platforms/platforms.json
plugins/**
!plugins/fetch.json

This ensures that only the two json files are tracked by git.这样可以确保 git 只跟踪两个 json 文件。 This is my platforms.json :这是我的platforms.json

{
    "ios": "3.9.1",
    "android": "4.1.1"
}

However, I thought that a cordova prepare would look into the platforms.json and would install the proper version automatically for my project.但是,我认为cordova prepare会查看platforms.json并为我的项目自动安装正确的版本。 The same would be very handy for the fetch.json inside the plugins directory.对于 plugins 目录中的fetch.json同样非常方便。 However, I noticed that here no versions, git commit hashes... are tracked, it just looks like this:但是,我注意到这里没有版本,git commit hashes... 被跟踪,它看起来像这样:

"cordova-plugin-console": {
    "source": {
        "type": "registry",
        "id": "cordova-plugin-console"
    },
    "is_top_level": true,
    "variables": {}
}

So my questions are:所以我的问题是:

  1. Is it best-practise to exclude platforms and plugins from the git repository?从 git 存储库中排除平台和插件是最佳实践吗?
  2. Is there (or will be) a bundler-like way, to lock plugins and platforms to a specific version, and just run a command, and everything gets installed?是否有(或将有)一种类似打包器的方式,将插件和平台锁定到特定版本,然后运行一个命令,然后一切都被安装了?
  3. What would be a good way, to not include the platforms and plugins directory, and share the project with other developers?什么是不包含平台和插件目录并与其他开发人员共享项目的好方法?
  1. I would say yes, so long as you set the versions of the platforms and plugins you want to use - keeping things that the CLI can generate out of source control is a good thing我会说是的,只要您设置要使用的平台和插件的版本 - 保留 CLI 可以在源代码控制之外生成的内容是一件好事

  2. Yes, you can use the @ notation for example:是的,您可以使用 @ 符号,例如:

    cordova platform add cordova-plugin-gelocation@1.0.1 cordova 平台添加cordova-plugin-gelocation@1.0.1

This applies to platforms as well, and each version of the Cordova CLI defaults to a specific version of the Cordova platform unless you override it.这也适用于平台,并且 Cordova CLI 的每个版本默认为 Cordova 平台的特定版本,除非您覆盖它。

Regarding running a command, I use hooks for this and have a post platform add hook that runs a script that installs all my plugins using the @ notation to get exactly the version I want.关于运行命令,我为此使用了钩子,并有一个 post 平台添加钩子,它运行一个脚本,该脚本使用 @ 符号安装我的所有插件,以获得我想要的版本。

  1. Follow the advice above and you should be able to do this.按照上面的建议,你应该能够做到这一点。 If you find yourself needing to manually modify anything in platforms folder in your project consider whether you can script this using the available build hooks before adding platforms to the source repository.如果您发现自己需要手动修改项目中平台文件夹中的任何内容,请考虑是否可以在将平台添加到源存储库之前使用可用的构建挂钩编写脚本。 If you find yourself altering plugins and thinking you need to check those in, then fork the plugin you are using, make your changes in the forked repo and use cordova plugin add to add your version of the plugin from your git repo or a local folder rather than polluting your main Cordova project repo.如果您发现自己更改了插件并认为需要检查这些插件,请分叉您正在使用的插件,在分叉的存储库中进行更改并使用 cordova plugin add 从您的 git 存储库或本地文件夹添加您的插件版本而不是污染您的主要 Cordova 项目存储库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM