Search code examples
typescriptionic-frameworkassets

Deploy JSON file with the app and access it on runtime


Is there a way to add a JSON file to my Ionic project and deploy it with the app to my device and then access it on runtime? I thought about using the assets folder but then again how would I retrieve the content of the assets folder within Typescript?


Solution

  • Deploy JSON file with the app and access it on runtime

    Options:

    Bundle it

    If you import it e.g. import x from './x.json' it will get built as a part of your bundle. Supported by webpack / ts-loader out of the box.

    Load it

    You can use fetch to load it at runtime e.g fetch('/assets/x.json').then(x=>x.json()).then(loaded => /*use it */).