# Files in www get deleted with every build

**URL:** <https://forum.ionicframework.com/t/files-in-www-get-deleted-with-every-build/65313>\
**Category:** ionic-v3\
**Created:** [October 1, 2016, 8:20am UTC](https://forum.ionicframework.com/t/files-in-www-get-deleted-with-every-build/65313 "2016-10-01T08:20:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joachim](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@Joachim](https://forum.ionicframework.com/u/Joachim)\
**Post date:** [October 1, 2016, 8:20am UTC](https://forum.ionicframework.com/t/files-in-www-get-deleted-with-every-build/65313/1 "2016-10-01T08:20:04Z")

</div>

Hi,

I have my sqlite db files in the www directory of my app, but since I upgraded to rc0 suddenly all files directly placed in www are deleted with each build. How can I now deploy my datafiles?

regards  
Joachim

---

<div class="post-metadata">

**Author:** ![sudharsan\_sukumar](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@sudharsan\_sukumar](https://forum.ionicframework.com/u/sudharsan_sukumar)\
**Post date:** [October 1, 2016, 8:26am UTC](https://forum.ionicframework.com/t/files-in-www-get-deleted-with-every-build/65313/2 "2016-10-01T08:26:06Z")

</div>

The assets folder under src gets included in the www folder. So if you had www/img/img.jpg before you can put the img/img.jpg folder in src/assets and then find it in www/assets/img/img.jpg.

Hope that helps!  
Dharsan

---

<div class="post-metadata">

**Author:** ![Joachim](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@Joachim](https://forum.ionicframework.com/u/Joachim)\
**Post date:** [October 1, 2016, 8:44am UTC](https://forum.ionicframework.com/t/files-in-www-get-deleted-with-every-build/65313/3 "2016-10-01T08:44:06Z")

</div>

Yes, for images and other file assets that is the way to go. But the SqlitePlugin expects the db file in the root www directory. As far as I know the window.sqlitePlugin.openDatabase does not allow a path for the filename, but I will try.

Joachim

---

<div class="post-metadata">

**Author:** ![BogdanC](https://avatars.discourse-cdn.com/v4/letter/b/a88e4f/32.png) [@BogdanC](https://forum.ionicframework.com/u/BogdanC)\
**Post date:** [October 3, 2016, 9:27pm UTC](https://forum.ionicframework.com/t/files-in-www-get-deleted-with-every-build/65313/4 "2016-10-03T21:27:02Z")

</div>

Hi.

I also have the same problem. Did you find any solution? I tried putting it in assets folder in src. I can’t find the assets folder on the phone after I install it. Any idea where it’s copied? Also, did you manage to open the db from a custom location?

Bogdan

---

<div class="post-metadata">

**Author:** ![brandyshea](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/brandyshea/32/148286_2.png) [@brandyshea](https://forum.ionicframework.com/u/brandyshea)\
**Post date:** [October 3, 2016, 10:47pm UTC](https://forum.ionicframework.com/t/files-in-www-get-deleted-with-every-build/65313/5 "2016-10-03T22:47:27Z")

</div>

So here is the config file for `copy` which runs with every build:

> <https://github.com/ionic-team/ionic-app-scripts/blob/master/config/copy.config.js>

The solution here would be to create your own config file and add whichever files you need copied over, similar to how `index.html` is copied (see the line with `my-file.db`):

```auto

// https://www.npmjs.com/package/fs-extra

module.exports = {
  include: [
    {
      src: 'src/assets/',
      dest: 'www/assets/'
    },
    {
      src: 'src/index.html',
      dest: 'www/index.html'
    },
    {
      src: 'src/my-file.db',
      dest: 'www/my-file.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/'
    },
  ]
};

```

Here is the documentation behind adding a custom config file: [https://github.com/driftyco/ionic-app-scripts#custom-config-files](https://github.com/driftyco/ionic-app-scripts#custom-config-files)

So you would save the above code as a file in your project, let’s call it `mycopy.config.js` for example, and then add it in your `package.json` with a path to the file. I saved it in the root of the project but you could have the config file anywhere in your project:

```auto
  "config": {
    "ionic_copy": "./mycopy.config.js"
  },
  "scripts": {
    ...
  },

```

Let me know if this doesn’t work for you! 🙂

---

<div class="post-metadata">

**Author:** ![BogdanC](https://avatars.discourse-cdn.com/v4/letter/b/a88e4f/32.png) [@BogdanC](https://forum.ionicframework.com/u/BogdanC)\
**Post date:** [October 4, 2016, 11:44am UTC](https://forum.ionicframework.com/t/files-in-www-get-deleted-with-every-build/65313/6 "2016-10-04T11:44:18Z")

</div>

This worked perfectly. Also, we have to use cordova-sqlite-ext instead of cordova-sqlite-storage, because it offers support for prepopulated db:

```
let db = window.sqlitePlugin.openDatabase({
    name: "your-db-name.db",
    location: 'default',
    createFromLocation: 1
});

```

Thanks,  
Bogdan

---

<div class="post-metadata">

**Author:** ![mattroth](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@mattroth](https://forum.ionicframework.com/u/mattroth)\
**Post date:** [October 5, 2016, 1:01am UTC](https://forum.ionicframework.com/t/files-in-www-get-deleted-with-every-build/65313/7 "2016-10-05T01:01:00Z")

</div>

This work around is require for anyone using cordova-hot-code-push and building from a remote repo. CHCP looks for the configuration at the root of the ‘www’ folder but in the most recent release of Ionic 2, the www folder is not checked into the repo and instead is created during build time. In our case, we use BuddyBuild to build directly from a repo and without a custom BuddyBuild script to create the chcp.json and chcp.manifest, they will not exist in the final app package. In the case of iOS, this causes the app to crash immediately after the splash screen.

Here is a crash report that finally shed light on this mystery for us:

Fatal Exception NSInvalidArgumentException

\*\*\* -[NSURL URLByAppendingPathComponent:isDirectory:]: component, components, or pathExtension cannot be nil.

FRAME MODULE CRASH DETAILS  
0 CoreFoundation   
\_\_exceptionPreprocess  
1 libobjc​.A​.dylib   
objc\_exception\_throw  
2 CoreFoundation   
+[NSException raise:format:]  
3 Foundation   
-[NSURL(NSURLPathUtilities) URLByAppendingPathComponent:isDirectory:]  
4 XxXX HCPFilesStructure.m ​Line ​66  
-[HCPFilesStructure localInitWithReleaseVersion:]  
5 XxXX HCPFilesStructure.m ​Line ​33  
-[HCPFilesStructure initWithReleaseVersion:]  
6 XxXX HCPPlugin.m ​Line ​150  
-[HCPPlugin doLocalInit]  
7 XxXX HCPPlugin.m ​Line ​52  
-[HCPPlugin pluginInitialize]  
8 XxXX   
-[CDVViewController registerPlugin:withClassName:]  
9 XxXX   
-[CDVViewController getCommandInstance:]  
10 XxXX   
-[CDVViewController viewDidLoad]  
11 XxXX MainViewController.m ​Line ​76  
-[MainViewController viewDidLoad]
