You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/how_tos/migrate-frontend-app.md
+14-32Lines changed: 14 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
Migrating an MFE to frontend-base
3
3
=================================
4
4
5
-
To use `frontend-base`, you'll need to use `npm pack` and install it into your MFE from the resulting `.tgz` file.
5
+
To use the latest version of `frontend-base` from a git repository, you'll need to use `npm pack` and install it into your MFE from the resulting `.tgz` file.
6
6
7
7
Following these steps turns your MFE into a library that can be built using frontend-base and its shell application. It involves deleting a lot of unneeded dependencies and code.
8
8
@@ -58,21 +58,19 @@ Dependencies shared with the shell should be moved to peerDependencies. These i
58
58
```diff
59
59
"dependencies" {
60
60
- "@openedx/paragon": "^22.8.1",
61
+
- "@tanstack/react-query": "^5.81.2",
61
62
- "react": "^17.0.2",
62
63
- "react-dom": "^17.0.2",
63
-
- "react-redux": "^8.1.3",
64
64
- "react-router": "^6.26.1",
65
65
- "react-router-dom": "^6.26.1",
66
-
- "redux": "^4.2.1"
67
66
},
68
67
"peerDependencies": {
69
68
+ "@openedx/paragon": "^22.8.1",
69
+
+ "@tanstack/react-query": "^5.81.2",
70
70
+ "react": "^17.0.2",
71
71
+ "react-dom": "^17.0.2",
72
-
+ "react-redux": "^8.1.3",
73
72
+ "react-router": "^6.26.1",
74
73
+ "react-router-dom": "^6.26.1",
75
-
+ "redux": "^4.2.1"
76
74
}
77
75
```
78
76
@@ -127,14 +125,10 @@ With the exception of any custom scripts, replace the `scripts` section of your
127
125
128
126
```
129
127
"scripts": {
130
-
"build": "openedx build",
131
128
"dev": "PORT=YOUR_PORT openedx dev",
132
129
"i18n_extract": "openedx formatjs extract",
133
130
"lint": "openedx lint .",
134
131
"lint:fix": "openedx lint --fix .",
135
-
"pack": "openedx pack",
136
-
"release": "openedx release",
137
-
"serve": "PORT=YOUR_PORT openedx serve",
138
132
"snapshot": "openedx test --updateSnapshot",
139
133
"test": "openedx test --coverage --passWithNoTests"
140
134
},
@@ -168,8 +162,6 @@ This means that the code from the library can be safely tree-shaken by webpack.
168
162
],
169
163
```
170
164
171
-
// TODO: Maybe put scss and css files in side effects. They have side effects and need to be excluded so they get bundled.
172
-
173
165
174
166
Add a Type Declaration file (app.d.ts)
175
167
======================================
@@ -294,9 +286,11 @@ Add a babel.config.js file for Jest
294
286
Jest needs a babel.config.js file to be present in the repository. It should look like:
@@ -542,7 +536,6 @@ App-specific configuration can be expressed by adding an `config` section to the
542
536
const app: App = {
543
537
...
544
538
config: {
545
-
appId: 'myapp',
546
539
myCustomVariableName: 'my custom variable value',
547
540
},
548
541
};
@@ -554,7 +547,7 @@ These variables can be used in code with the `getAppConfig` function:
554
547
getAppConfig('myapp').myCustomVariableName
555
548
```
556
549
557
-
Or via `useAppConfig()` (with no need to specify the appId), if `AppProvider` is wrapping your app.
550
+
Or via `useAppConfig()` (with no need to specify the appId), if `CurrentAppProvider` is wrapping your app.
558
551
559
552
560
553
Replace the .env.test file with configuration in site.config.test.tsx file
@@ -625,8 +618,7 @@ Export the modules of your app in your index.ts file.
625
618
626
619
This may require a little interpretation. In spirit, the modules of your app are the 'pages' of an Open edX Frontend site that it provides. This likely corresponds to the top-level react-router routes in your app. In frontend-app-profile, for instance, this is the `ProfilePage` component, amongst a few others. Some MFEs have put their router and pages directly into the `index.jsx` file inside the initialization callback - this code will need to be moved to a single component that can be exported.
627
620
628
-
These modules should be unopinionated about the path prefix where they are mounted. The exact way we handle routing is still being figured out. In the short term, the react-router data APIs are not suppored until we can figure out how to implement lazy route discovery (a.k.a., "Fog of War") Using `<Routes>` with `<Route>` components inside it works today. **This functionality is still a work in progress, and is one of the big things we need to figure out.**
629
-
621
+
These modules should be unopinionated about the path prefix where they are mounted.
630
622
631
623
Remove core-js and regenerator-runtime
632
624
======================================
@@ -639,7 +631,7 @@ Create a site.scss file
639
631
640
632
This is required if you intend to run builds from the app itself.
641
633
642
-
Create a new `site.scss` file at the top of your application. It's responsible for:
634
+
Create a new `app.scss` file at the top of your application. It's responsible for:
643
635
644
636
1. Importing the shell's stylesheet, which includes Paragon's core stylesheet.
645
637
2. Importing your brand stylesheet.
@@ -648,7 +640,7 @@ Create a new `site.scss` file at the top of your application. It's responsible
648
640
You must then import this new stylesheet into your `site.config` file:
649
641
650
642
```diff
651
-
+ import './site.scss';
643
+
+ import './app.scss';
652
644
653
645
const siteConfig: SiteConfig = {
654
646
// config document
@@ -721,6 +713,8 @@ Upgrade react-query
721
713
722
714
If the MFE uses react-query version 4 or below, upgrade it to 5 as per [this guide](https://tanstack.com/query/latest/docs/framework/react/guides/migrating-to-v5).
723
715
716
+
If the MFE uses Redux, consider porting the app over to react-query, as it will make it much easier to handle header (and footer) customization.
717
+
724
718
725
719
Removal of pubsub-js
726
720
====================
@@ -742,16 +736,4 @@ Refactor plugin-slots
742
736
743
737
First, rename `src/plugin-slots`, if it exists, to `src/slots`. Modify imports and documentation across the codebase accordingly.
744
738
745
-
Next, the frontend-base equivalent to `<PluginSlot />` is `<Slot />`, and has a different API. This includes a change in the slot ID, according to the [new slot naming ADR](../decisions/0009-slot-naming-and-lifecycle.rst) in this repository. Rename them accordingly. You can refer to the `src/shell/dev-site` in this repository for examples.
746
-
747
-
748
-
Find your module boundaries
749
-
===========================
750
-
751
-
From this step on, things get a bit more subjective. At this point you need to ensure that the modules in your library are decoupled and well-bounded. If you use Redux, this may mean creating individual redux stores for each module, including adding a context so that they're separate from any "upstream" redux stores that may exist.
Next, the frontend-base equivalent to `<PluginSlot />` is `<Slot />`, and has a different API. This includes a change in the slot ID, according to the [new slot naming ADR](../decisions/0009-slot-naming-and-lifecycle.rst) in this repository. Rename them accordingly. You can refer to the `src/shell/dev` in this repository for examples.
0 commit comments