Ionic-native: Unable to install a workable version of ionic-native that contains a new experimental plugin

Created on 27 Apr 2016  路  6Comments  路  Source: ionic-team/ionic-native

Hi! I wonder why everytime I tried to install the custom version of ionic-native, with my plugin.ts and updated index.ts file included, it just doesn't work. I realized npm install ionic-native --save is installing a very different thing than what it's displayed here. For example, for each plugin.ts, it has a .js.map and some other file. This just never happens when I'm trying to install my own version of Ionic-Native.

I wonder how is it possible to test my newly developed plugin without submitting and forking? Thank you!

Most helpful comment

We should document this and maybe also add a watch task.

@kdenz after building ionic-native locally, run npm link from the ionic-native project root to create a global symlink to your local version, then from your app's directory run npm link ionic-native to replace the one in node_modules that you got from npm with the global symlink.

Steps:

  • cd ionic-native && npm install
  • npm run build_bundle
  • npm link
     
  • cd myapp
  • npm link ionic-native

Then any imports like import {Camera} from 'ionic-native' will use the symlinked version that points to your local ionic-native.

All 6 comments

Installing via NPM would get you the NPM package, not what you see here on Github. The master branch here is more like a development branch (for now).

To build it yourself, clone the repo, run npm install to install any development dependencies and then run the command npm run build_bundle to compile the library. Then you will see the files in the dist directory.

I hope that helped, let me know if you have any further questions.

@ihadeed Thanks! : D It seems to work. And I wonder if there's a more efficient way of developing/testing individual wraps? For example, adding a new .ts file todist/plugins, update the index and then run npm run build_bundle again?

Not sure what the most efficient way is. But this is what I do:

I have a blank Ionic 2 app in another directory. Both the app and ionic-native are located in the same parent directory. The Ionic app imports ionic-native from ../ionic-native/dist/index. Then I follow these steps every time I want to test something out:

  1. Run npm run build_bundle to build my new library (I can really skip this an import ../ionic-native/src/ but I do this to catch any build errors)
  2. Install any needed plugins to the Ionic app
  3. Run the Ionic app on my Android device
  4. Use Chrome remote debugging (chrome://inspect) to control the app through the console

When I'm in the console, I just call the apps using IonicNative global variable. Example: IonicNative.Camera.getPicture(...).then(...)


Do let me know if you think of a more efficient way!

We should document this and maybe also add a watch task.

@kdenz after building ionic-native locally, run npm link from the ionic-native project root to create a global symlink to your local version, then from your app's directory run npm link ionic-native to replace the one in node_modules that you got from npm with the global symlink.

Steps:

  • cd ionic-native && npm install
  • npm run build_bundle
  • npm link
     
  • cd myapp
  • npm link ionic-native

Then any imports like import {Camera} from 'ionic-native' will use the symlinked version that points to your local ionic-native.

Just note for anyone else stumbling across this, it's now:

````
cd ionic-native && npm install
npm run build && npm run build:bundle
npm link

cd myapp
npm link ionic-native

````

Was this page helpful?
0 / 5 - 0 ratings