frontend-app-api: extract createApp out into frontend-defaults

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-08-28 14:02:26 +02:00
parent fc66073fa4
commit 7c80650a1e
27 changed files with 643 additions and 169 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ Below is a simple example of how to create and render an app instance:
```ts
import ReactDOM from 'react-dom/client';
import { createApp } from '@backstage/frontend-app-api';
import { createApp } from '@backstage/frontend-defaults';
// Create your app instance
const app = createApp({
@@ -295,7 +295,7 @@ export default createExtensionOverrides({
Assuming the above code resides in the `@internal/search-page` package, you can install it in your app like this:
```tsx title="packages/app/src/App.tsx"
import { createApp } from '@backstage/frontend-app-api';
import { createApp } from '@backstage/frontend-defaults';
import searchPageOverride from '@internal/search-page';
const app = createApp({
@@ -256,7 +256,7 @@ app:
We also have the ability to express this in code as an option to `createApp`, but you of course only need to use one of these two methods:
```tsx title="packages/app/src/App.tsx"
import { createApp } from '@backstage/frontend-app-api';
import { createApp } from '@backstage/frontend-defaults';
import catalog from '@backstage/plugin-catalog';
import scaffolder from '@backstage/plugin-scaffolder';
@@ -30,13 +30,13 @@ The created-app is currently templated for legacy frontend system applications,
## The app instance
The starting point of a frontend app is the `createApp` function, which accepts a single options object as its only parameter. It is imported from `@backstage/frontend-app-api`, which is where you will find most of the common APIs for building apps.
The starting point of a frontend app is the `createApp` function, which accepts a single options object as its only parameter. It is imported from `@backstage/frontend-defaults`, which is where you will find most of the common APIs for building apps.
This is how to create a minimal app:
```tsx title="in src/index.ts"
import ReactDOM from 'react-dom/client';
import { createApp } from '@backstage/frontend-app-api';
import { createApp } from '@backstage/frontend-defaults';
import catalogPlugin from '@backstage/plugin-catalog/alpha';
// Create your app instance
@@ -87,7 +87,7 @@ Previously you would customize the application routes, components, apis, sidebar
A manual installation is required if your packages are not discovered automatically, either because you are not using `@backstage/cli` to build your application or because the features are defined in local modules in the app package. In order to manually install a feature, you must import it and pass it to the `createApp` function:
```tsx title="packages/app/src/App.tsx"
import { createApp } from '@backstage/frontend-app-api';
import { createApp } from '@backstage/frontend-defaults';
// This plugin was create as a local module in the app
import { somePlugin } from './plugins';
@@ -104,10 +104,10 @@ You can also pass overrides to the features array, for more details, please read
### Using an async features loader
In case you need to perform asynchronous operations before passing features to the `createApp` function, define a [feature loader](https://backstage.io/docs/reference/frontend-app-api.createappfeatureloader/) object and pass it to the `features` option:
In case you need to perform asynchronous operations before passing features to the `createApp` function, define a [feature loader](https://backstage.io/docs/reference/frontend-defaults.createappfeatureloader/) object and pass it to the `features` option:
```tsx title="packages/app/src/App.tsx"
import { createApp } from '@backstage/frontend-app-api';
import { createApp } from '@backstage/frontend-defaults';
const app = createApp({
features: {
@@ -129,7 +129,7 @@ export default app.createRoot();
In some cases we want to load our configuration from a backend server and to do so, you can pass an callback to the `configLoader` option when calling the `createApp` function, the callback should return a promise of an object with the config object:
```tsx title="packages/app/src/App.tsx"
import { createApp } from '@backstage/frontend-app-api';
import { createApp } from '@backstage/frontend-defaults';
import { getConfigFromServer } from './utils';
// Example lazy loading the app configuration
@@ -18,7 +18,7 @@ The first step in migrating an app is to switch out the `createApp` function for
// highlight-remove-next-line
import { createApp } from '@backstage/app-defaults';
// highlight-add-next-line
import { createApp } from '@backstage/frontend-app-api';
import { createApp } from '@backstage/frontend-defaults';
```
This immediate switch will lead to a lot of breakages that we need to fix.