-
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 patches to 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
292 additions
and
1 deletion.
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
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
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,53 @@ | ||
{{- 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 in iter_slots() %} | ||
{%- if patch("mfe-env-config-plugin-{}".format(slot_name)) %} | ||
{{ slot_name }}: { | ||
keepDefault: true, | ||
plugins: [ | ||
{{- patch("mfe-env-config-plugin-{}".format(slot_name)) }} | ||
] | ||
}, | ||
{%- endif %} | ||
{%- endfor %} | ||
} | ||
}; | ||
|
||
{%- for app_name, app in iter_mfes() %} | ||
if (process.env.npm_package_name == '@edx/frontend-app-{{ app_name }}') { | ||
{%- if patch("mfe-env-config-dynamic-imports-{}".format(app_name)) %} | ||
{{- patch("mfe-env-config-dynamic-imports-{}".format(app_name)) }} | ||
{%- endif %} | ||
|
||
{%- for slot_name in iter_slots() %} | ||
{%- if patch("mfe-env-config-plugin-{}-{}".format(app_name, slot_name)) %} | ||
config.pluginSlots.{{ slot_name }}.plugins.push( | ||
{{- patch("mfe-env-config-plugin-{}-{}".format(app_name, slot_name)) }} | ||
); | ||
{%- endif %} | ||
{%- endfor %} | ||
} | ||
{%- endfor %} | ||
|
||
{{- patch("mfe-env-config-tail") }} | ||
} catch { } | ||
|
||
return config; | ||
} | ||
|
||
export default getConfig; |