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

@W-15458727@ [App Extensibility ⚙️] Asset Support #2040

Closed bendvc closed 4 days ago

bendvc commented 4 days ago

Description

It's important that when you are developing an Application Extension that you are able to both add assets to your extension code as well as access those extensions. In this PR we modify the Web Pack configuration to ensure that all assets places in an Application Extensions /static folder are bundled with all the other assets.

Additionally we want to create a utility to allow developers to access these static assets. Here we created a new utility called getStaticAssetUrl that will return a url to a static asset provided it's relative path. Optionally you can pass in any extensions package name that will be used to access that static asset in the extensions folder.

NOTE: This isn't an ideal API and having to pass in the the package name will get tedious. However this is the groundwork to hopefully come up with a react-y hooks api where we can simple do something like useStaticAssetUrl() and it will just know what extension you are in. But unfortunately I wasn't able to get something like that in the time given for this ticket.

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