NPM软件包在Cordova/PhoneGap中的用法 [英] Usage of npm packages in cordova / phonegap

查看:84
本文介绍了NPM软件包在Cordova/PhoneGap中的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用NPM将软件包添加到我的Cordova项目中,但是我做错了什么或者我没有弄清楚它应该如何工作……我正在使用最新版本的Cordova(v3 .5.0).我已经创建了一个应用程序:

I’m trying to add a package to my Cordova project using NPM, but either I’m doing something terribly wrong or I’m not getting the way it should work… I’m using the latest version of Cordova (v3.5.0). I have created an application:

cordova create TestApp
cd TestApp
cordova platform add android
cordova run android

一切正常,该应用程序出现在我的Android设备上.现在,我想将包"pako"添加到我的应用中: https://github.com/nodeca/pako.我仍然在同一目录中(请参见上文),然后输入"npm install pako".该软件包安装在"/node_modules/"中.

Everything works perfectly, and the app appears on my Android device. Now I want to add the package ‘pako’ to my app: https://github.com/nodeca/pako. I’m still in the same directory (see above) and I enter "npm install pako". The package is installed in "/node_modules/".

但是,当我为Android构建应用程序(cordova构建android/cordova运行android/cordova prepare)时,没有将我已安装的软件包(在"/node_modules/"目录中)复制到平台特定的文件夹"platforms/安卓/….".换句话说,如何在Cordova/Phonegap应用程序中使用npm软件包?科尔多瓦cli不应该将这个软件包自动复制到正确的平台上吗?

However, when I build my application for Android (cordova build android / cordova run android / cordova prepare), none of my installed packages (in the "/node_modules/" directory) is copied to the platform specific folder "platforms/android/….". In other words, how to use a npm package in a Cordova / Phonegap application? Shouldn’t this package be copied automatically by the cordova cli to the right platform?

这有可能吗?或者,例如,当我想使用npm软件包时,是否必须使用Grunt创建手动构建脚本?由于找不到任何示例,因此我认为自己完全走错了道路,因此,如果有人能向正确的方向提供帮助,我将不胜感激.

Is this possible at all? Or do I have to create a manual build script using Grunt for example when I want to use npm packages? Since I can’t find any examples, I have the idea that I’m completely on the wrong track, so if anyone has a little hint to help me in the right direction, I would be very grateful.

提前谢谢!

推荐答案

这可以通过使用在before_prepare触发的钩子来实现.

This is possible by using a hook triggered before_prepare.

请参见 https://stackoverflow.com/a/46615080/2728710

这篇关于NPM软件包在Cordova/PhoneGap中的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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