Skip to content

Commit 4cc9ad7

Browse files
committed
chore: adjust example app to use new build tools
1 parent 7de0df0 commit 4cc9ad7

7 files changed

+27
-62
lines changed

examples/test-app/src/assets/testPath/pre-load-module-fed-mods.json

-7
This file was deleted.

examples/test-app/src/assets/testPath/test-app-fed-mods.json

-7
This file was deleted.

examples/test-app/src/assets/testPath/test-module-fed-mods.json

-7
This file was deleted.

examples/test-app/src/entry.tsx

+9-13
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,10 @@ const config: AppsConfig<{ assetsHost?: string }> = {
1616
manifestLocation: '/assets/testPath/foo/bar/nonsense.json',
1717
assetsHost: 'http://localhost:8888',
1818
},
19-
testApp: {
20-
name: 'testApp',
21-
manifestLocation: '/assets/testPath/test-app-fed-mods.json',
22-
},
23-
testModule: {
24-
name: 'testModule',
25-
manifestLocation: '/assets/testPath/test-module-fed-mods.json',
26-
},
27-
preLoad: {
28-
name: 'preLoad',
29-
manifestLocation: '/assets/testPath/pre-load-module-fed-mods.json',
30-
},
3119
'sdk-plugin': {
3220
name: 'sdk-plugin',
33-
manifestLocation: '/plugin-manifest.json',
21+
assetsHost: 'http://localhost:8001',
22+
manifestLocation: 'http://localhost:8001/plugin-manifest.json',
3423
},
3524
};
3625

@@ -40,6 +29,13 @@ const Entry = () => {
4029
pluginSDKOptions={{
4130
pluginLoaderOptions: {
4231
transformPluginManifest(manifest) {
32+
const host = config[manifest.name]?.assetsHost;
33+
if (host) {
34+
return {
35+
...manifest,
36+
loadScripts: manifest.loadScripts.map((script) => `${host}/${script}`),
37+
};
38+
}
4339
return {
4440
...manifest,
4541
loadScripts: manifest.loadScripts.map((script) => `${script}`),

examples/test-app/src/routes/LegacyModules.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ const LegacyModules = () => {
2424

2525
const handlePreload = async () => {
2626
try {
27-
await preloadModule('preLoad', './PreLoadedModule');
27+
await preloadModule('sdk-plugin', './PreLoadedModule');
2828
} catch (error) {
2929
console.log('Unable to preload module: ', error);
3030
}
3131
};
3232

3333
const handlePreloadPF = async () => {
3434
try {
35-
await preloadModule('testApp', './ModuleOne');
35+
await preloadModule('sdk-plugin', './ModuleOne');
3636
} catch (error) {
3737
console.log('Unable to preload module: ', error);
3838
}
@@ -79,20 +79,20 @@ const LegacyModules = () => {
7979
<GridLayout margin={[10, 10]} className="layout" layout={layout} cols={2} width={852}>
8080
<div key="initial">
8181
<BoxWrapper>
82-
<ScalprumComponent LoadingComponent={LoadingComponent} scope="testApp" module="./ModuleOne" />
82+
<ScalprumComponent LoadingComponent={LoadingComponent} scope="sdk-plugin" module="./ModuleOne" />
8383
</BoxWrapper>
8484
</div>
8585
{showPreLoadedModule && (
8686
<div key="preLoad">
8787
<BoxWrapper>
88-
<ScalprumComponent LoadingComponent={LoadingComponent} scope="preLoad" module="./PreLoadedModule" />
88+
<ScalprumComponent LoadingComponent={LoadingComponent} scope="sdk-plugin" module="./PreLoadedModule" />
8989
</BoxWrapper>
9090
</div>
9191
)}
9292
{showPreLoadedModuleWPF && (
9393
<div key="preFetch">
9494
<BoxWrapper>
95-
<ScalprumComponent LoadingComponent={LoadingComponent} scope="testApp" module="./ModuleOne" />
95+
<ScalprumComponent LoadingComponent={LoadingComponent} scope="sdk-plugin" module="./ModuleOne" />
9696
</BoxWrapper>
9797
</div>
9898
)}

examples/test-app/src/routes/RuntimeErrorRoute.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const RuntimeErrorRoute = () => {
66
return (
77
<div>
88
<h2>Runtime error route</h2>
9-
<ScalprumComponent LoadingComponent={LoadingComponent} scope="testApp" module="./ErrorModule" />
9+
<ScalprumComponent LoadingComponent={LoadingComponent} scope="sdk-plugin" module="./ErrorModule" />
1010
</div>
1111
);
1212
};

examples/test-app/webpack.config.ts

+12-22
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
import { withNx, NxWebpackExecutionContext, composePluginsSync } from '@nx/webpack';
44
import { withReact } from '@nx/react';
55
import { merge } from 'webpack-merge';
6-
import { Configuration, container, ProgressPlugin } from 'webpack';
6+
import { Configuration, ProgressPlugin } from 'webpack';
77
import { join, resolve } from 'path';
8-
import { DynamicRemotePlugin } from '@openshift/dynamic-plugin-sdk-webpack';
9-
10-
const { ModuleFederationPlugin } = container;
8+
import { ModuleFederationPlugin } from '@module-federation/enhanced';
9+
import { DynamicRemotePluginEnhanced } from '@scalprum/build-tools/src/index';
1110

1211
const sharedModules = {
1312
react: {
@@ -28,18 +27,12 @@ const sharedModules = {
2827
},
2928
};
3029

31-
const TestAppFederation = new ModuleFederationPlugin({
32-
name: 'testApp',
33-
filename: 'testApp.js',
30+
const ShellConfig = new ModuleFederationPlugin({
31+
name: 'shell',
32+
filename: 'shell.[contenthash].js',
3433
library: {
35-
type: 'var',
36-
name: 'testApp',
37-
},
38-
exposes: {
39-
'./ModuleOne': resolve(__dirname, './src/modules/moduleOne.tsx'),
40-
'./ModuleTwo': resolve(__dirname, './src/modules/moduleTwo.tsx'),
41-
'./ModuleThree': resolve(__dirname, './src/modules/moduleThree.tsx'),
42-
'./ErrorModule': resolve(__dirname, './src/modules/errorModule.tsx'),
34+
type: 'global',
35+
name: 'shell',
4336
},
4437
shared: [
4538
{
@@ -63,7 +56,7 @@ const TestPreLoadFederation = new ModuleFederationPlugin({
6356
name: 'preLoad',
6457
filename: 'preLoad.js',
6558
library: {
66-
type: 'var',
59+
type: 'global',
6760
name: 'preLoad',
6861
},
6962
exposes: {
@@ -77,7 +70,7 @@ const TestModuleFederation = new ModuleFederationPlugin({
7770
name: 'testModule',
7871
filename: 'testModule.js',
7972
library: {
80-
type: 'var',
73+
type: 'global',
8174
name: 'testModule',
8275
},
8376
exposes: {
@@ -87,13 +80,10 @@ const TestModuleFederation = new ModuleFederationPlugin({
8780
shared: [sharedModules],
8881
});
8982

90-
const TestSDKPLugin = new DynamicRemotePlugin({
83+
const TestSDKPLugin = new DynamicRemotePluginEnhanced({
9184
extensions: [],
9285
sharedModules,
9386
entryScriptFilename: 'sdk-plugin.[contenthash].js',
94-
moduleFederationSettings: {
95-
libraryType: 'global',
96-
},
9787
pluginMetadata: {
9888
name: 'sdk-plugin',
9989
version: '1.0.0',
@@ -104,7 +94,7 @@ const TestSDKPLugin = new DynamicRemotePlugin({
10494
});
10595

10696
const withModuleFederation = (config: Configuration, { context }: NxWebpackExecutionContext): Configuration => {
107-
const plugins: Configuration['plugins'] = [new ProgressPlugin(), TestSDKPLugin, TestAppFederation, TestModuleFederation, TestPreLoadFederation];
97+
const plugins: Configuration['plugins'] = [new ProgressPlugin(), ShellConfig];
10898
const newConfig = merge(config, {
10999
experiments: {
110100
outputModule: true,

0 commit comments

Comments
 (0)