Install node dependencies for Cordova plugin

I am 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 the dependencies listed.

Does Cordova support this function in some way? Did I miss something?

My current solution is another hook that triggers after_plugin_install :

 module.exports = function (context) { var shell = context.requireCordovaModule('shelljs'); shell.cd(context.opts.plugin.dir); shell.exec('npm install'); }; 
+7
cordova cordova-plugins
source share
1 answer

I want to add npm modules to a Cordova project, you do not need a plugin, just use the hook fired before_prepare .

This hook will start the entire npm installation for each cordova prepare (also for cordova run , cordova compile , etc.).

You do not need to create a JS file for the hook, a linux script shell is enough (although it is less portable). I prefer to use the just.sh file when I only need to do "npm install" or something like this.

0
source share

All Articles