How to make SQLite in ionic-native use cordova-sqlite-ext?

Even if you manually put your db file inside the www folder, there’s no guarantee it will be copied to the final build apk. At least, that’s what was happening with me.

I had to leverage Ionic’s config script system to get past that problem. Basically, Ionic provides you the option to create a custom config file to specify extra files you want copied in the build.

Just create copy.config.js inside the config folder in your app’s root. Here’s my config file’s content. Try reusing this. (You will need to have your db file in the src folder)

module.exports = {
  include: [
    {
      src: '{{SRC}}/assets/',
      dest: '{{WWW}}/assets/'
    },
    {
      src: '{{SRC}}/index.html',
      dest: '{{WWW}}/index.html'
    },
    {
      src: '{{SRC}}/manifest.json',
      dest: '{{WWW}}/manifest.json'
    },
    {
      src: '{{SRC}}/service-worker.js',
      dest: '{{WWW}}/service-worker.js'
    },
    {
      src: 'node_modules/ionic-angular/polyfills/polyfills.js',
      dest: '{{BUILD}}/polyfills.js'
    },
    {
      src: 'node_modules/ionicons/dist/fonts/',
      dest: '{{WWW}}/assets/fonts/'
    },
    {
      src: '{{SRC}}/my.db',
      dest: '{{WWW}}/my.db'
    }
  ]
};
1 Like