ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
51.05k stars 13.51k forks source link

Ionic 2 RC0 Pre-Populated databases #8583

Closed iursevla closed 8 years ago

iursevla commented 8 years ago

In ionic beta 11 i would put the pre-populated database on /www folder and use cordova-sqlite-ext plugin with options:

let options = { name: 'myDatabase.db', existingDatabase: true };

Now in RC0, it won't work because everytime we run (ionic run...) the www folder is overwritten. I tried to put it on /src OR in /src/assets but with no luck in both cases.

So, where should i put pre-populated databases in ionic 2 RC0 ?

stellasoft-charlie commented 8 years ago

Ionic supports writing custom config files - https://github.com/driftyco/ionic-app-scripts#custom-config-files . This will let you write your own js file where you can declare everything you would like to copy over into the www directory. create a file along side your package.json called for example, copy.config.js , inside this add the following:

module.exports = { include: [ { src: 'src/assets/', dest: 'www/assets/' }, { src: 'src/index.html', dest: 'www/index.html' }, { src: 'src/uki.db', dest: 'www/uki.db' }, { src: 'src/service-worker.js', dest: 'www/service-worker.js' }, { src: 'node_modules/ionic-angular/polyfills/polyfills.js', dest: 'www/build/polyfills.js' }, { src: 'node_modules/ionicons/dist/fonts/', dest: 'www/assets/fonts/' }, ] }; `

Then in your package.json add a config option with the following.

"config": { "ionic_copy": "./copy.config.js" },

Put the pre-populated DB in the src folder and it will copy it over along with the rest of the files

jgw96 commented 8 years ago

Hello! Thanks for opening an issue with us! As this seems like more of a support question i will urge that you ask this question on our forum and take a look at the app-scripts docs. Thanks for using Ionic!

jgw96 commented 8 years ago

Hello! I am going to reopen this issue and move it to the app-scripts repo. We are reviewing the current setup where www is treated as a throw away directory and I will use this issue to post our findings. Thanks!

jgw96 commented 8 years ago

This issue was moved to driftyco/ionic-app-scripts#127