Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions README-ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,43 @@ interface UikitPluginOptions {
}
```

### Remote Versions

Добавляет информацию о версиях микрофронтендов на страницу.

Этот плагин создает глобальный объект `window.__REMOTE_VERSIONS__`, содержащий указанные версии микрофронтендов, который может использоваться module federation или аналогичными архитектурами микрофронтендов для определения того, какие версии удаленных модулей загружать.

Он может использоваться в связке с [App Builder](https://github.com/gravity-ui/app-builder?tab=readme-ov-file#module-federation) и опцией `moduleFederation.remotesRuntimeVersioning` для автоматической загрузки удаленных модулей с соответствующими версиями.

Использование:

```js
import {createRenderFunction, createRemoteVersionsPlugin} from '@gravity-ui/app-layout';

const renderLayout = createRenderFunction([createRemoteVersionsPlugin()]);

app.get((req, res) => {
res.send(
renderLayout({
title: 'Home page',
pluginsOptions: {
remoteVersions: {
header: '1.2.3',
footer: '2.1.0',
sidebar: '0.5.1',
},
},
}),
);
});
```

Параметры плагина:

```typescript
type RemoteVersionsPluginOptions = Record<string, string>;
```

### Утилиты

Для создания плагинов используется предустановленная утилита:
Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,43 @@ interface UikitPluginOptions {
}
```

### Remote Versions

Adds microfrontend versions information to the page.

This plugin creates a global `window.__REMOTE_VERSIONS__` object containing the provided microfrontend versions, which can be used by module federation or similar microfrontend architectures to determine which versions of remote modules to load.

It can be used in combination with [App Builder](https://github.com/gravity-ui/app-builder?tab=readme-ov-file#module-federation) and the `moduleFederation.remotesRuntimeVersioning` option to automatically load remote modules with the corresponding versions.

Usage:

```js
import {createRenderFunction, createRemoteVersionsPlugin} from '@gravity-ui/app-layout';

const renderLayout = createRenderFunction([createRemoteVersionsPlugin()]);

app.get((req, res) => {
res.send(
renderLayout({
title: 'Home page',
pluginsOptions: {
remoteVersions: {
header: '1.2.3',
footer: '2.1.0',
sidebar: '0.5.1',
},
},
}),
);
});
```

Plugin options:

```typescript
type RemoteVersionsPluginOptions = Record<string, string>;
```

### Helpers

There is helper to create all plugins:
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {
createYandexMetrikaPlugin,
createLayoutPlugin,
createUikitPlugin,
createRemoteVersionsPlugin,
createDefaultPlugins,
} from './plugins/index.js';

Expand All @@ -33,3 +34,4 @@ export type {
} from './plugins/google-analytics/index.js';
export type {LayoutPluginOptions, Manifest, LayoutInitOptions} from './plugins/layout/index.js';
export type {UikitPluginOptions} from './plugins/uikit/index.js';
export type {RemoteVersionsPluginOptions} from './plugins/remote-versions/index.js';
2 changes: 2 additions & 0 deletions src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {createGoogleAnalyticsPlugin} from './google-analytics/index.js';
import {createLayoutPlugin} from './layout/index.js';
import type {LayoutInitOptions} from './layout/index.js';
import {createRemoteVersionsPlugin} from './remote-versions/index.js';
import {createUikitPlugin} from './uikit/index.js';
import {createYandexMetrikaPlugin} from './yandex-metrika/index.js';

Expand All @@ -18,4 +19,5 @@ export {
createYandexMetrikaPlugin,
createLayoutPlugin,
createUikitPlugin,
createRemoteVersionsPlugin,
};
25 changes: 25 additions & 0 deletions src/plugins/remote-versions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import htmlescape from 'htmlescape';

import type {Plugin} from '../../types.js';

import type {RemoteVersionsPluginOptions} from './types.js';

export type {RemoteVersionsPluginOptions} from './types.js';

export function createRemoteVersionsPlugin(): Plugin<
RemoteVersionsPluginOptions,
'remoteVersions'
> {
return {
name: 'remoteVersions',
apply({options: versions, renderContent}) {
if (!versions) {
return;
}

renderContent.inlineScripts.push(
`window.__REMOTE_VERSIONS__ = ${htmlescape(versions)};`,
);
},
};
}
1 change: 1 addition & 0 deletions src/plugins/remote-versions/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type RemoteVersionsPluginOptions = Record<string, string>;
Loading