1

I've been using Angular for a while, but I'm new to Ionic. Recently, I started a project.

My project folder is as follows

I added a folder named mocks which holds some mock json files. I want to be able to retrieve these files from http://localhost:8100/mocks/my-mock-data.json which I could not have done.

Coming from angular-cli, I thought I should add mocks folder to some config so that ionic-lab can serve files from this folder.

In .angular-cli.json, you would add your custom folders to apps[0].assets array, so angular-cli can serve them. I thought it would be similar in ionic too, so I tried to add my mocks folder to ionic.config.json. However, I could not find how to (I'm not even sure this is the right place to add it)

Then, I tried to find a schema for ionic.config.json so that I can get some intellisense on VsCode and maybe I can find the right config myself. However, I could not find schema for ionic.config.json as well.

Then, I googled for how to set ionic configs. I came across their website They give some examples but not the full list.

Input       Description
property    The property name you wish to set
value       The new value of the given property

So, my questions are

  1. How can I serve some mock files from ionic-lab?
  2. What are the full set of properties and corresponding values in ionic.config.json?
Bunyamin Coskuner
  • 8,719
  • 1
  • 28
  • 48

1 Answers1

1

You cannot serve files like that in ionic. Note that ionic simply combines everything in one main.js file, and assets are bundled separately. When ionic serve or ionic cordova run are invoked, it ultimately calls an NPM script. These npm scripts call the @ionic/app-scripts library to execute the build process.

To use dummy data, you can simply place dummy data in any folder inside src > assets folder. Lets say you put it in src > assets > example_data folder as json file. Note that you can also save these files with services or pages.

Now, a service in say dummydata-service.ts under src > providers can reference it for test usage like

GetDummyData(): Promise<any> {
  return this.http.get('./assets/example_data/dummyData.json')
   .toPromise()
   .then(response => {return response.json()})
   .catch(this.handleError);
}

On the point of ionic.config.json, it is not analogous to .angular-cli.json. This is an Ionic project config file which stores configuration values consumed by certain ionic.io services. Important keys being app_id, name, typescript.

RKalra
  • 531
  • 7
  • 10
  • So, it has some config hidden inside for assets folder. It feels like I should be able to add another folder. However it is not that important. About `ionic.config.json`, I know it is different than `.angular-cli.json`. ı just want to know which properties I can set in `ionic.config`. I could not find the full list. – Bunyamin Coskuner Feb 17 '18 at 18:20
  • Ionic.config stores project information. When you use ionic commands like `link`, `login`, etc. (refer https://ionicframework.com/docs/cli/commands.html) then the properties used by ionic.io services get stored here. You would never need to edit them unless you plan on changing ionic service parameters. This might interest you: http://legacy.docs.ionic.io/docs/io-config – RKalra Feb 17 '18 at 19:54
  • @BunyaminCoskuner Do accept the answer if it answered your question. – RKalra Mar 12 '18 at 10:31
  • It did not fully answer my question. I still don't know how to configure `ionic.config.json` I mean what properties it has and how to set them. – Bunyamin Coskuner Mar 12 '18 at 10:33
  • It is mainly required by Ionic Services offered by Ionic Pro. In order to work with these services from cli, the framework requires certain parameters for the app, which are stored in the `ionic.config.json`. These parameters include `name`, `app_id`, `v2`, and `typescript`. They get configured when you call any ionic command that requires usage of (now called) Ionic Pro Services. Try calling `ionic login` followed by `ionic link` from cli. – RKalra Mar 12 '18 at 10:43