question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multi-app projects config

See original GitHub issue

Branching off main issue re: project structure configurability: https://github.com/ionic-team/ionic-cli/issues/2232

We can add support in the Ionic CLI for multi-app projects.

@PoiScript summed it up nicely:

The primary problem is that we can not specify which project to use with ionic-cli

These multi-app projects are typically in the shape of monorepos which have multiple apps and libraries.

  • For now, let’s assume all apps are of the same project type: angular. This means a shared angular.json at the root of the monorepo.
  • The starters come with an angular.json. Not a big deal, but it would need to be deleted

The builders in ng-toolkit were built with Angular 6 tooling, so they support any project structure that the Angular CLI does. The issue is how do we map ionic serve and related project commands to the requested project such that Ionic and Angular know which project to use.

These commands already have a --project and --configuration option to configure which map to configuration within angular.json. I think all we need to do is read angular.json, use the key from --project and find the project root and then look for ionic.config.json inside the specified directory.

cc @stupidawesome

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

11reactions
stupidawesomecommented, Jun 5, 2018

Working on a proof of concept that should enable support for multi-app workspaces by adding additional configuration to ionic.config.json.

Constraints:

  1. The workspace consists of a single monorepo with multiple apps and libraries.
  2. Each Ionic β€œproject” should map to one angular β€œproject” of the same name.
  3. Additional configuration is needed to enable a multi-app workspace.
  4. Existing apps should continue to work without introducing new breaking changes.
  5. Potentially support other project types

Case Study: Given the following ionic.config.json configuration:

{
    "defaultProject": "first-app",
    "projects": {
        "first-app": {
            "type": "angular",
            "integrations": {
                "cordova": {
                    "root": "integrations/first-app/cordova"
                }
            }
        },
        "second-app": {
            "type": "angular",
            "integrations": {
                "cordova": {
                    "root": "integrations/second-app/cordova"
                },
                "capacitor": {
                    "platforms": {
                        "electron": {
                            "root": "integrations/second-app/electron"
                        }
                    }
                }
            }
        }
    }
}

And the following extract from angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "",
  "projects": {
    "first-app": {
      "root": "projects/first-app/"
    },
    "second-app": {
      "root": "projects/second-app/"
    }
  }
}

We can produce the following directory structure:

.
β”œβ”€β”€ projects
|   β”œβ”€β”€ first-app
|   └── second-app
β”œβ”€β”€ integrations
|   β”œβ”€β”€ first-app
|   |   └── cordova
|   |       β”œβ”€β”€ build.json
|   |       β”œβ”€β”€ config.xml
|   |       β”œβ”€β”€ platforms
|   |       |   β”œβ”€β”€ ios
|   |       |   └── android
|   |       β”œβ”€β”€ plugins
|   |       β”œβ”€β”€ resources
|   |       └── www
|   └── second-app
|       β”œβ”€β”€ cordova
|       └── electron
β”œβ”€β”€ node_modules
β”œβ”€β”€ angular.json
β”œβ”€β”€ ionic.config.json
└── package.json

When running Ionic commands, the defaultProject will be used if it isn’t specified using the --project flag. The goal is to also make it possible to β€œswitch” projects from the CLI via ionic config set defaultProject or something similar. Note that the defaultProject from angular.json will not be used.

The root key is important as it sets the current working directory for cordova. Capacitor integration here is only illustrative and not part of this proof of concept.

With this configuration and directory structure in place, we can now run some commands:

Generate resources for the second app

ionic cordova resources --project second-app

Add platform for the second app

ionic cordova platform add ios --project second-app

Build the first app (via ng-toolkit)

# Can omit --project since it's the defaultProject
ionic cordova build ios

And so on…

Existing Apps: The current proposal is strictly opt-in, meaning that existing Ionic apps will continue to work without making any changes to ionic.config.json. To make this possible the CLI will look for the projects key in the configuration file to determine whether the workspace is set up for single or multiple apps. Migration however should be easy, and new projects could potentially be generated in the newer format.

To migrate an existing app to the new configuration schema:

{
  "defaultProject": "app",
  "projects": {
     "app": { ...yourCurrentConfig }
   }
}

Other considerations:

  • This assumes a single git repo without submodules for application code.
  • This assumes a single root level node_modules for sharing dependencies. We might need additional package.json files for storing cordova config/dependencies?
  • Only considering angular project types for now.
6reactions
imhoffdcommented, Jul 30, 2018

Hi all! πŸ‘‹ Ionic 4 was released! (see the announcement on our blog)

But, I still have to write some documentation about a multi-app config for CLI 4. We wanted to make the experience for single-app repos solid first. Please be patient, and thanks for subscribing to this issue for updates!

πŸ“ One bonus: with this, we can also document how to modify angular.json to customize project structure! πŸŽ‰

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple apps in a single project - Platform.sh Documentation
Create multiple apps within a single project, such as a CMS backend ... You want multiple apps from the same source code, Unified...
Read more >
Multi-app projects config Β· Issue #691 Β· ionic-team/capacitor
Ionic and Angular use an extra configuration file at the root of each project. I think that capacitor should have too.
Read more >
Multi-App Projects - Adopting Erlang
This configuration is meant specifically for the grpcbox_plugin that is declared in the top-level's rebar.config , but allows the plugin to onlyΒ ...
Read more >
Configure multiple projects | Firebase - Google
Configure multiple projects ... This page describes how to use more than one Firebase project in your app. Many apps need only a...
Read more >
Building an Ionic Multi App Project with Shared Angular Library
The result for now looks like the image below. ionic-multi-repo-setup To prepare the workspace for our Ionic apps, go ahead and create a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found