Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import ionic.native.js in Ionic V1/Angular 1.x

It's getting hard to see documents or examples now that Ionic 2 is out.

I want to use ionic.native.js in the old Ionic V1 project. Thing is that the installation is with npm

npm install ionic-native --save

But now I have tons of npm modules under node_modules/ as a dependency. Ionic documentation say:

If you are using Angular 1.x or plain ES5 JavaScript, you need to add ionic.native.js to your index.html

but they don't give example on "how" to place it in the index.html - and that is my question.

Currently my file is located in:

> find . -name ionic.native.js
./node_modules/ionic-native/dist/ionic.native.js

There's no gulp task for the node_modules/ dir ... so how do I import it into index.html ? or maybe I used the npm command in the wrong place ? ( currently it's in the root dir of the project, where gulpfile.js lives )

like image 493
Ricky Levi Avatar asked Jul 31 '16 11:07

Ricky Levi


2 Answers

I was having the same problem as you.

In the end, what ended up solving it was using:

bower install ionic-native --save

This adds the files to the lib/ directory, which is accessible from the index page.

Then in the index.html file, add:

<script src="lib/ionic-native/ionic.native.js"></script>

Hopefully this helps!

like image 195
Greg Avatar answered Oct 20 '22 08:10

Greg


If you want to use npm instead of bower, you can add a path to desired location when installing the plugin:

npm install ionic-native --save --prefix www/lib
like image 35
Davor Avatar answered Oct 20 '22 07:10

Davor