Ionic Angular Multi App Project
Ionic Angular Multi App Project
Creating
Follow a Multi App Project Workspace
We could start with an Ionic app and remove some of the files,
but it’s actually easier to create a workspace with the Angular
72
CLI for which we can also add a flag to not create any
application.
1 This will create just a re barebones project with
some files, so start with that:
1 # Create a workspace
2 ng new devdacticMulti --createApplication=false
3 cd ./devdacticMulti
4
5 # Create our projects directory
6 mkdir projects
Now all the Ionic apps that we generate will be added to the
projects key of that file, and we can alter simply select one of
them to run by passing a flag. Make sure that you navigate
your command line into the projects folder for the next
commands as otherwise the apps would be in the wrong place.
Now you have a projects folder with 2 Ionic projects, a good
start so far. If you were to follow the official guide, it wouldn’t
work yet as the projects would not be found.
Now the Ionic CLI can find and build the right project, so all
you have to do to run one of your apps is call the standard serve
command and add the --project flag with the name of the
project you want to run!
...
...
It ends with a failure, and at this point you can’t build your
Cordova app in the multi app project. The problem is that the
ionic.config.json file (currently) adds the integrations key to
the top-level object, and somehow not to the respective
problem.
You will see that it now works, and the platforms/ folder is
created inside the projects directory!
This also means you can simply have the according resources
like icon and splashcreen in each of the projects and they don’t
override each other. No additional magic or copy task needed
to configure your client project!
You always have to run the build command at least once for the
library, but if you are working on it, it makes sense to simply
watch all changes and it will rebuild immediately on safe.
Right now you can’t use the library in the Ionic projects as they
don’t really know about it, and the import path would be
wrong or not work at all.
To fix this new problem, you can open the projects Typescript
config, for example the projects/appOne/tsconfig.json and
change it to:
Now we can easily go ahead and use that library in our appOne
project, so open the
projects/appOne/src/app/home/home.module.ts and add
it like this:
Note that you should use the name academy-lib without any
path, which your IDE might want to tell you. If you added the
TS config before correctly, this works now!
Now you can make changes to the lib while running watch and
Ionic serve, and you get a sense of why this approach can be
really powerful!
Feeling Fancy?
If you don’t enjoy how Ionic looks as a website, perhaps you
want a standard Angular website? No problemo!
Conclusion
There’s not a lot of information on the topic of Ionic multi app
projects, but they can be really powerful if you can make them
work for your white label solution or perhaps simply for having
the Ionic app and website in one project.