Install node dependencies for Cordova plugin

风流意气都作罢 提交于 2019-12-23 07:36:52

问题


I'm writing a Cordova plugin, it has a node dependency for one of the hook scripts. Ideally when my plugin is installed:

$ cordova plugin add my-cordova-plugin

I would like it to run npm install if package.json has dependencies listed.

Does Cordova support this feature in some way? Have I missed something?

My current solution is another hook that runs after_plugin_install:

module.exports = function (context) {
    var shell = context.requireCordovaModule('shelljs');

    shell.cd(context.opts.plugin.dir);
    shell.exec('npm install');
};

回答1:


I you're looking for to add npm modules to your Cordova project, you don't need a plugin, juste use a simple hook triggered before_prepare.

This hook will run all the npm install you need for each cordova prepare (also for cordova run, cordova compile, etc..).

You don't have to make a JS file for a hook, a linux shell script is enough (although it is less portable). I prefer to use juste .sh file when my only need is to do "npm install" or stuff like that.



来源:https://stackoverflow.com/questions/31290828/install-node-dependencies-for-cordova-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!