The purpose of this document is to provide an overview of how micro-frontend applications (MFEs) are developed, configured, and deployed with the Open edX ecosystem. Open edX MFEs are small React applications that can be built and deployed independently.
To run an MFE locally you must install node 12 (with npm version 6.11 or higher). All MFEs offer the following commands:
npm install (install dependencies) npm start (development server) npm run lint npm run test npm run build (build static output)
Open edX MFEs expect a number of process environment variables (Accessible in node via
process.env) in order to properly configure authentication, routing to other parts of the system, etc. Each MFE has
.env.test files that are consumed by the MFE. The production .env file contains only null values – the build process should supply them via the command line prior to running
npm run build.
NODE_ENV='development' PORT=1995 ACCESS_TOKEN_COOKIE_NAME='edx-jwt-cookie-header-payload' BASE_URL='localhost:1995' CREDENTIALS_BASE_URL='http://localhost:18150' CSRF_TOKEN_API_PATH='/csrf/api/v1/token' ECOMMERCE_BASE_URL='http://localhost:18130' LANGUAGE_PREFERENCE_COOKIE_NAME='openedx-language-preference' LMS_BASE_URL='http://localhost:18000' LOGIN_URL='http://localhost:18000/login' LOGOUT_URL='http://localhost:18000/login' MARKETING_SITE_BASE_URL='http://localhost:18000' ORDER_HISTORY_URL='localhost:1996/orders' REFRESH_ACCESS_TOKEN_ENDPOINT='http://localhost:18000/login_refresh' SEGMENT_KEY=null SITE_NAME='edX' USER_INFO_COOKIE_NAME='edx-user-info'
MFEs contain Open edX branded headers, footers and style. To build a MFE to reflect the brand of the particular Open edX instance some npm dependencies are designed to be overridden. Overriding packages must expose the same interface as the dependencies they are overriding.
Example: for edx.org the Open edX @edx/frontend-component-header is overridden with @edx/frontend-component-header-edx using npm aliases (introduced in npm version 6.9.0). Example syntax below:
# Syntax: npm install <package-name>@<type>:<branded-package> # npm package npm install @edx/frontend-component-header@npm:@edx/frontend-component-header-edx@latest # git repository npm install @edx/frontend-component-header@git:https://github.com/edx/frontend-component-header-edx.git # local folder npm install @edx/frontend-component-header@file:../path/to/local/module
A list overridable packages is being developed. Currently only @edx/frontend-component-header and @edx/frontend-component-footer are designed to be overridden. See those repositories for the interfaces they expose.
The basic deployment strategy:
NODE_ENV=development BASE_URL=open.edx.org ETC=etc npm run build
dist/directory is created that contains the deployable artifacts.
dist/to a web server.
Note: The following is edX-specific and depends upon automation set up in GoCD. A similar, more manual process will need to be defined for Open edX installations.
edX MFEs are deployed automatically upon updates to the master branch in Github. GoCD collects three materials: the MFE source code, .yml configuration, and pipeline scripts (edX tubular).
.yml configuration contains:
Relevant pipeline scripts (edX tubular):
The pipeline scripts perform a routine like below:
npm install @edx/pkg@npm:custom-pkg
NODE_ENV=development BASE_URL=open.edx.org npm run build