-
Notifications
You must be signed in to change notification settings - Fork 659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-App Configuration Issue #4121
Comments
@Domvel The Ionic CLI doesn't have opinions about how you structure your monorepo. People could choose to have apps connected with a single Remember, the CLI docs (aside from command reference) don't assume you're using Angular. One could create Ionic React apps alongside Ionic Angular apps and the multi-app feature would continue to work, blissfully unaware of the project's internals. If you don't want these config files in your apps, delete them and make it work for your preferences. |
I actually hit this issue last night. I have a mono-repo which contains back end code and multiple front end apps, the general structure is something like the following
I came to add $ ionic start --no-deps
? Project name: apps/app3
? Starter template: sidemenu The cli then went and made an app called I was wondering if it would be possible for the cli to infer values from an existing For instance, if creating a new angular ionic app, then the cli could use the Or, leave the |
@johneast The As for the Right now we use an old-fashioned way of starting projects. We download an archive that contains a working app, and make file changes from there. The Angular CLI and Vue CLI both use a more modern approach, where files and their contents are conditionally provisioned in a template/logic-based approach. I would argue if we're going to start making changes to framework-based files (which change constantly, i.e. |
@dwieeb Then what is the Ionic CLI doing? Kinda detecting that If the end result is that I still have to make manual changes to various angular.json(s) and modify them accordingly, shouldn't I have to do that for my ionic.config.json(s) as well? And if I have to do that, why bother with this ionic CLI at all? What's extremely difficult to get past is that the docs as they stand today leave us with a non-functioning app. I understand there's a world of flexibility in setting up a monorepo, so maybe the CLI can't just create one, but if that's the case, could we work to build some example apps that others could leverage as a starting point? |
I think it's also worth noting that the ionic CLI, generally speaking, is opinionated about how an app is structured. So we're all used to running But then this multi-tenant philosophy, without opinions, comes out of left field and leaves everyone spinning not knowing what to do. |
@Domvel - it seems odd your apps each have an |
@josh-m-sharpe To be clear, I agree. I understand how Angular monorepos are expected to work, and that What's implemented now is a bare-bones effort to get the Ionic CLI to even operate in a monorepo, which wasn't easy to begin with. Step 2 is adding intelligence around the framework files, which in my opinion requires us to rethink our starters. Luckily, Step 1 allowed the Ionic CLI to be flexible enough for power users to do what they needed to do.
Yeah, we're missing a full tutorial for setting up an Ionic Angular monorepo, which would utilize the multi-app feature and the Angular monorepo feature. The docs as they are today are meant to be a reference for how the Ionic CLI deals with multiple apps in a project (not how to setup an opinionated, full-featured monorepo). We haven't pushed this feature very hard because it still requires manual work, but we should still have the documentation for what exists today. If you like, we can use your issue to track that. |
@dwieeb Thanks for the reply. I appreciate how awkward it can be to code against frameworks that can change at any given time. The process at the moment is a little awkward, however it is workable and the fact that once the projects in the repo are all set up everything works is great. I like the sound of #3499. It definitely sounds like the way to go in order to make Some documentation or walkthroughs about how to setup a mono-repo and add ionic projects to it would be good. I'd be happy to contribute if need be. |
Now I have my multi-app. 😓 But can't execute Does not work: ionic cordova run android --project=app1
Workspace
Background of my workspace: But the Ionic commands does not work. I think the ionic.config.json {
"name": "my-apps",
"integrations": {
"cordova": {}
},
"type": "angular",
"projects": {
"app1": {
"name": "App1",
"integrations": {
"cordova": {}
},
"type": "angular",
"root": "src/apps/app1"
},
"app2": {
"name": "App2",
"integrations": {
"cordova": {}
},
"type": "angular",
"root": "src/apps/app2"
}
}
} Any my angular.json is also set up well, I think. Angular serve works well. What are the criteria for the error message?
If I run |
@Domvel I just walked through this again. Here's my repo: https://github.com/dwieeb/ionic-multiapp I ran into a couple weird things with integrating Cordova, which must've been recent bugs, so I fixed them up: 167a68c and 4e8a226 I'm not getting the "can only be run in an Ionic project directory" error that you're seeing, though. Could you go through my steps and see where we might differ? |
@dwieeb Thanks. Yes, I did the same, more or less. I created the sub-apps manually without Here is my workspace demo. ng serve works. It's a reduced minimal application from my original project. I hope I didn't missed anything. The philosophy of this project is to avoid code repetition. Also for the project setup. I don't want the same stuff for each app as copy. I use one setup and only load different Angular modules. Angulars apps only differs from the bootstrapped module. Only one package.json, tsconfig.ts etc. Also only one Cordova Android for both apps. The app-id is replaced later automatically in Jenkins or manually by scripts. The apps are really identically by the base. Only a few pages etc. are different. This should work. Maybe the problem is that the apps do not have projects-setups like the root. I don't want a package.json etc. for each app. That's nonsense in my case. Because each app uses the same deps, same base etc. It sould only build the Angular app and wrap it in Cordova for Android. But what's wrong? ionic info
[ERROR] Error while loading config (project config: .\ionic.config.json)
Unknown project file structure. Run ionic init to re-initialize your Ionic project. Without a valid project
config, the CLI will not have project context.
[WARN] You are not in an Ionic project directory. Project context may be missing.
Ionic:
Ionic CLI : 5.2.5
Utility:
cordova-res : not installed
native-run : 0.2.8
System:
NodeJS : v10.15.3
npm : 6.4.1
OS : Windows 10
ionic init
? Project name: my-apps
[OK] Your Ionic project has been initialized! (ionic init without changes.) |
Ok, now I am one step further. From: {
"name": "my-apps",
"integrations": {
"cordova": {}
},
"type": "angular",
"projects": {
"app1": {
"name": "App 1",
"integrations": {
"cordova": {}
},
"type": "angular",
"root": "src/apps/app1"
},
"app2": {
"name": "App 2",
"integrations": {
"cordova": {}
},
"type": "angular",
"root": "src/apps/app2"
}
}
} to: {
"projects": {
"app1": {
"name": "App 1",
"integrations": {
"cordova": {}
},
"type": "angular",
"root": "src/apps/app1"
},
"app2": {
"name": "App 2",
"integrations": {
"cordova": {}
},
"type": "angular",
"root": "src/apps/app2"
}
}
} Now Ionic tells me what is wrong or what it is expecting. ionic cordova run android --project=app1
√ Creating .\src\apps\app1\www directory for you - done!
[ERROR] Cannot load Cordova config.
Could not find necessary file(s): config.xml, package.json.
- .\src\apps\app1\config.xml
- .\src\apps\app1\package.json
You can re-add the Cordova integration with the following command: ionic integrations enable cordova --add Hmmm 🤔 It looks like I have to create the package.json and config.xml stuff for each app. But is there a way to use this what is in my root folder? As I wrote. Each app should use the same deps and Android config. The app-id, name, resources, etc. will be changed later by scripts. (e.g. Jenkins) I understand why it needs separated package.json and config.xml. Because of the name and id. But the rest is equal to each app. I don't want copies. UPDATE: UPDATE 2: Here's the current branch about Cordova Android build. But on runtime it fails on localhost connection refused. Maybe I have to set up each app with the complete package json and deps. But I don't like it. Because as I wrote: I have to manage the same stuff in each app. This is really annoying and error prone. Can I set the package and config xml in ionic.config.json? A common use for all apps. Now I'm with NX to check this way. I see that there is only one package.json in the root. But each app have separated tslint.json (but extends from root tslint file). But because of the missing package.json in the apps directory, Ionic will fail too. I think we have to change this. Ionic Cordova should work with multi-apps monorepos like from NX created. Maybe Xplat is the solution. Update: I tried nx. Ionic fails because requires the package.json for each sub-app. -.- TL;DR: At this moment I have a working "multi-app" monorepo. With 2 apps but 3 package json with exactly the same deps. One for app1, one for app2 and one for the lib folder. ... |
A workaround (more or less) could be to refer the packages in the dummy package of an Ionic App. (Inspired by Xplat). Not tested. (I'll test it next week).
The root A app package json: {
"name": "foobar",
"version": "0.0.0",
"dependencies": {
"@ionic/angular": "file:../../node_modules/@ionic/angular",
"rxjs": "file:../../node_modules/rxjs",
"zone.js": "file:../../node_modules/zone.js",
"...": "etc. this is just a comment from me. :)"
}
} But note: Xplat uses Ionic Capacitor for the apps. There fore no config.xml is required at this place. Also note that you need the |
This is an Angular mutli app and library workspace: Created by the commands:
Note that there is no need for a package.json for the library folder. It's created e.g. because you could export this library as npm package. Generelly there is no need to have multiple package.json files in your workspace. See app1 and app2 they have no package.json. Ionic Cordova should repect this workspace (multi-app / monorepo) structure and behavior. This is generated by Angular and official recommended. Ionic v4 is still a special Angular project. Especially the Cordova part. This should be fixed by:
Generally we want only one project / workspace setup with one place to manage the dependencies. And do not repeat your self. (DRY). So we do not want to have the same configurations for each app in the workspace. Unfortunately the angular.json is still "messy". In my opinion it should be a js-file to reuse configurations. You could handle it with a node js-file. But I do not want special "hacks". Follow the mainstream / the standards to reduce the project maintenance. |
@dwieeb What are the build commands of Ionic CLI doing? (see below)
Is this possble? Trigger the build manually in separated parts? My scripts (maybe not up to date. It's from Ionic v3. But I think they have not changed.): Run on Android Build for Android Update: Ok, I built the Angular project and build the Cordova app. I have a white screen. I have put a text between the Do we need the script-tag |
Hey, I've got the same problem. I'm refactoring multiples apps in a monorepo using angular 8 and ionic 4. I could use the ng serve or ionic serve perfectly using the --project argument but i'm totally unable to build or run using ionic cordova command. It failed saying that i can't find the project. |
@youuri It's because Ionic requires a |
@Domvel i got a dumb package.json in each of my apps with the cordova config & plugins in it. I also have a config.xml in each project and it worked as i want in this case. But when i run So i think i got a configuration issue between |
@youuri Maybe you should use the command without quotes?
{
"projects": {
"app1": {
"name": "App 1",
"integrations": {
"cordova": {}
},
"type": "angular",
"root": "apps/app1"
}
} ONLY the btw: In my case I only have the angular.json and no ionic.config.json. (as I wrote above). I'll upload a demo now to my repo. |
A multi-app monorepo build by the official guides of the docs of Angular. Using Ionic for UI and native plugin wrapper and the webview (required for Angular). And build with Cordova. No Ionic CLI. Note: You have to change the app id in config.xml for each app. You can do it automatically by a node script or a build system like Jenkins. Disclaimer: Maybe it's not comfortable to add more Cordova plugins. Because proberply you have to complete the integration on installing new plugins. Install the plugins by Cordova, not Ionic. Maybe you have to add the plugins to config.xml too. But this is simple, just look to the package.json. If you want to install new plugins from the Ionic docs. Just remove the |
I'm not sure it's viable in my case. I'll need to have a config.xml & package.json for each ionic app cause they not share all the sames plugins. But it could be if the apps shared the same stack. |
I think there is not the only one workspace setup. It depends on what you want. I have common dependencies because each app uses the same base app (shared lib) and they only differ from the main page etc. But if you have completely different apps who uses separate dependencies like your setup, you need a package.json and config.xml for each app. Another way is to export a shared library as npm package and use separate repositories with a simple single app Ionic setup and use the shared lib using npm package. One repo for the libs, and a repo for each app. This stops some Monorepo problems, but brings other problems. Such as the use of Angular modules. Especially in conjunction with 3rd party libraries, build and import problems, etc. No system is perfect. You will always have advantages and disadvantages. Either from your source code, IDE or workflow. You have to choose what is the right way for your application. - I have followed the principle of NX and Xplat, but uses the official Angular way for multi-app without the NX stuff to have a lightweight and less special setup. Only the Ionic Cordova CLI brought me some problems. Conclusion: There is no perfect way to develop multiple apps with the same code base (shared library). There is always one component in your source code, your IDE or build system that causes problems or you have to do without a feature. For Ionic CLI I just wish some more options to use Cordova for single deps like in my monorepo. I think this could be done by setting some paths and maybe a config file for each app to manage the app id and name. ... |
This flag automates the setup steps for multi-app projects (see the docs: https://ionicframework.com/docs/cli/configuration#multi-app-projects). Although this feature was built largely with Angular monorepos in mind, it is flexible for all project types. See this wiki article for examples of how to use this feature in Angular: https://github.com/ionic-team/ionic-cli/wiki/Angular-Monorepo ref: #4121 ref: #4192
👋 Hey all, please see this comment and this wiki article for the latest on Ionic multi-app projects and Angular Monorepos. Using |
It seems to be related to that: |
We're doing research into Ionic; created a new React Ionic app; there's no config anywhere; adding it manually does nothing? Any ideas? |
@ollyde Have you found a solution? |
@Rossella-Mascia-Neosyn I started using Svelte with Capacitor. Both SSR and SPA; it's excellent. |
Can you explain how you did it? |
@Rossella-Mascia-Neosyn sure but I'm not in software anymore after 20 years; in hardware now, so this might be outdated.
Here's my build SPA bash script for example
|
Describe the bug
https://ionicframework.com/docs/cli/configuration#config-file
Is this correct for the latest version of Ionic?
I created the multi-apps with
no-deps
parameter and both apps also have their ownionic-config.json
. Also .gitignore, tslint.json, package.json.To Reproduce
ionic start my-apps
(blank template)ionic.config.json
and add the property"projects": {}
.ionic start app1 --no-deps
. (app1 and app2) (blank template)ionic.config.json
.Expected behavior
I'm not sure how the multi-app feature of Ionic works.
I though I have a root project with all the project files like
package.json
andionic.config.json
.And the "sub-apps" only contains the sources without separated configuration files etc.
Ok they can have a package.json. But why are there all the dependencies, even though the root dependencies should be used? Or do I understand something wrong? Or is the documentation wrong?
Screenshots
If applicable, add screenshots to help explain your problem.
Browser and OS (please complete the following information):
Additional context
I want to create one app base (root) with multi-app feature. Each apps should use the shared root components, services, etc. But an app can also have their own components.
TSLint, TSConfig, Unit-Test-Config, gitignore, etc. should be shared. But currently each subapp have a own config. Exactly the same. DRY.
Maybe this is a bug for the Ionic core repository or CLI? But perhaps it's only a documentation issue. I don't know who this should actual work. This is my first attempt of building a multi-app.
But the fact is, each app in a multi-app project has its own ionic.config.json. The docs says there should only be one shared in the root. Or does this mean, I should delete the config files in my sub-apps?
The text was updated successfully, but these errors were encountered: