alphagov / govuk-prototype-kit

Rapidly create HTML prototypes of GOV.UK services
https://prototype-kit.service.gov.uk
MIT License
303 stars 236 forks source link

Make any npm module a plugin via a proxy plugin config #2382

Closed BenSurgisonGDS closed 9 months ago

BenSurgisonGDS commented 9 months ago

I've had a several requests from people to allow npm modules to load their script, sass files and assets as they would a plugin.

A designer was trying to use the npm module browser-fs-access but was having difficulty loading the scripts from node_modules. This PR adds support for a new json file /app/plugin-proxy.json that contains a proxy plugin config for the module that treats the npm module as a plugin which solved his issue neatly:

{
    "browser-fs-access": {
        "scripts": {
            "type": "module",
            "path": "/dist/index.modern.js"
        }
    }
}

I'm suggesting this be introduced as it will not affect anyone who has not created the /app/plugin-proxy.json file with a view to documenting the use of this at a later date. For now it gets over the issue of wanting something to be a plugin without hard coding it for everyone.

gazjoy commented 9 months ago

Hello folks, just for some additional context it was me who was trying to install the JS module.

My use case is around testing different ways in which users expect to get a copy of their application as mentioned in this issue: https://github.com/alphagov/govuk-design-system-backlog/issues/234

We're looking at how we might show users a "save as" dialog so they are at less risk of losing the mental model of where a download goes.