SalesforceCommerceCloud / pwa-kit

React-based JavaScript frontend framework to create a progressive web app (PWA) storefront for Salesforce B2C Commerce.
https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/pwa-kit-overview.html
BSD 3-Clause "New" or "Revised" License
283 stars 130 forks source link

[App Extensibility ⚙️] Bundle All Installed Extensions #2004

Closed bendvc closed 3 weeks ago

bendvc commented 3 weeks ago

Description

During conversations with @adamraya I uncovered an issue in bundling our Application Extensions in the PWA-Kit app. The problem stems from the fact that we build the application on the the local developers environment before shipping the pre-built artifact to MRT. This means that we don't know what environment this code will be run on.

This poses a problem because the configured extensions during the build time might be different than the ones required for runtime. For example, I build the code on my local environment and it uses the configuration file, default.js which has app extension A, and B installed and configured. I then push my code to the production environment which has its own configuration file, production.js. This configuration file has app extensions B and C configured.

What happens is that the app extension C will never be loaded as it was never included in the bundle.

The solution (for now) is to ensure that all Application Extensions are bundled during build, we do this by ensuring all the extensions that are installed (in the dev-dependencies list) are imported. But only those that are configured at returned via a new getExtensions function that is exported in the extensions.js file.

NOTE: I have added another Application Extension project in the repo for testing purposes, this will be deleted before merging the code.

NOTE: We will most certainly want to investigate dynamic loading of app extensions for the front end. The reason being is that for large large projects that want to have almost mutually exclusive application extension configurations per configuration will end up with lost of unused code in their bundle. We can solve this with dynamic extension loading.

Types of Changes

Changes

How to Test-Drive This PR

Checklists

General

Accessibility Compliance

You must check off all items in one of the follow two lists:

or...

Localization