I am starting a project that requires multiple distinct ionic apps that share a significant amount of code.
I am trying to figure out an optimal way of organizing my code in order to streamline development. I have set up my project with a folder structure similar to this:
- my-project
- apps
- app-1
- app-2
- core
- apps
/apps/app-1
and /apps/app-2
are each complete Ionic2 apps.
/core
holds an Angular module with components, directives, providers, etc., that are to be used by app-1
and app-2
.
I am importing components in app-1
using relative import paths such as:
import {CoreDataProvider, CoreComponent1} from "../../../../../core";
This basically works, but I have some problems, in particular when using live-reload with ionic serve
.
In order to streamline my workflow, I need to be able to save changes to my code in the core
module, and see the effect of those changes in my browser. Currently this does not work.
If I save changes in core
and reload my browser, the changes are not reflected, because the ionic serve
watcher does not see the changes outside of the apps/app1
folder.
Even more problematic is the fact that changes in the core module are not picked up even if I trigger a rebuild in the app-1
folder by saving a code file there.
- in terminal
$ cd apps/app-1
$ ionic serve
- make and save a change to a component or provider in
/core
- make and save a change to a file in /apps/app1
- observe a new build triggered by
ionic serve
and the app reload in the browser - the changes to the component are not reflected in the new build
- go back to terminal, hit ctrl-c and run a new
$ ionic serve
- the changes to the component are now reflected in the new build
So it seems that the external core
module is getting cached as a part of the build process and doesn’t get refreshed by ionic serve
when it is changed.
Is there any way I can fix this, perhaps with modifications to the build scripts? Ideally I would like to figure out how to have changes in the core
folder trigger a new build with the changes reflected. However, even if the watcher wasn’t observing the core
folder but I could trigger a build by re-saving a file inside my app folder and then see the changes from the core
module, it would be a big improvement.
Any help with this would be greatly appreciated.