【问题标题】:Can we use yarn for adding capacitor plugin我们可以使用纱线添加电容器插件吗
【发布时间】:2023-05-20 23:32:01
【问题描述】:

我正在使用纱线依赖项进行反应项目。需要将电容器插件添加到反应项目中。但是添加电容器插件和链接存在问题 电容器到项目。要创建电容器插件,我使用命令“npx @capacitor/cli plugin:generate”。我可以使用纱线添加插件吗?我参考文档-https://capacitorjs.com/docs/plugins/creating-plugins

【问题讨论】:

  • 这是工作吗??

标签: hadoop-yarn capacitor npx capacitor-plugin


【解决方案1】:

capacitor.config.json 中设置"npmClient" : "yarn"

这是一个完整的例子

{
  "appId": "com.example.test",
  "appName": "Example",
  "bundledWebRuntime": false,
  "npmClient": "yarn",
  "webDir": "dist",
  "plugins": {
    "SplashScreen": {
      "launchShowDuration": 3000
    }
  },
  "cordova": {}
}

【讨论】:

    【解决方案2】:

    应该可以。您已经通过npx 创建了插件。因此,为了进行测试,请将文档中的 npm 命令替换为 yarn。对于local testing

    在你的插件文件夹中

    $ yarn link
    

    然后在电容器项目中测试你的插件:

    $ yarn link plugin-name
    $ yarn install plugin-name
    

    【讨论】:

    • 感谢您的评论。但是在创建电容器插件之后。需要使用“npm run build”来构建它,我应该在那里使用纱线命令。我使用纱线。它返回错误。请帮助遇到使用纱线创建电容器