-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support frontend plugins via env.config.jsx
This provides a mechanism to configure frontend plugins using a new PLUGIN_SLOTS filter and a series of patches that modify a base `env.config.jsx`, in such a way that multiple plugins can take advantage of the file (including for purposes beyond frontend plugins) without clobbering each other.
- Loading branch information
Showing
6 changed files
with
231 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
changelog.d/20241111_172451_arbrandes_frontend_plugin_support.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- [Improvement] Adds support for frontend plugin slot configuration via env.config.jsx. (by @arbrandes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{{- patch("mfe-env-config-static-imports") }} | ||
|
||
{{- patch("mfe-env-config-head") }} | ||
|
||
async function getConfig () { | ||
let config = {}; | ||
|
||
try { | ||
/* We can't assume FPF exists, as it's not declared as a dependency in all | ||
* MFEs, so we import it dynamically. In addition, for dynamic imports to | ||
* work with Webpack all of the code that actually uses the imported module | ||
* needs to be inside the `try{}` block. | ||
*/ | ||
const { DIRECT_PLUGIN, PLUGIN_OPERATIONS } = await import('@openedx/frontend-plugin-framework'); | ||
{{- patch("mfe-env-config-dynamic-imports") }} | ||
|
||
config = { | ||
pluginSlots: { | ||
{%- for _, slot_name, slot_config in iter_plugin_slots("all") %} | ||
{{ slot_name }}: { | ||
keepDefault: true, | ||
plugins: [ | ||
{{- slot_config }} | ||
] | ||
}, | ||
{%- endfor %} | ||
} | ||
}; | ||
|
||
{%- for app_name, app in iter_mfes() %} | ||
if (process.env.npm_package_name == '@edx/frontend-app-{{ app_name }}') { | ||
{{- patch("mfe-env-config-dynamic-imports-{}".format(app_name)) }} | ||
|
||
{%- for _, slot_name, slot_config in iter_plugin_slots(app_name) %} | ||
config.pluginSlots.{{ slot_name }}.plugins.push( | ||
{{- slot_config }} | ||
); | ||
{%- endfor %} | ||
} | ||
{%- endfor %} | ||
|
||
{{- patch("mfe-env-config-tail") }} | ||
} catch { } | ||
|
||
return config; | ||
} | ||
|
||
export default getConfig; |