alphagov / govuk-prototype-kit

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

Support assets compilation at build time #2341

Open smeny opened 12 months ago

smeny commented 12 months ago

Context

We have a prototype hosted with AWS ECS and we followed the instructions to publish it in “production” mode (https://prototype-kit.service.gov.uk/docs/publishing). We are trying to keep resources to a minimum but we noticed that assets are compiled each time the container starts which delays the startup getting our container CPU to 100%.

We think compilation is done here but we couldn't find a way to call this function directly from our prototype.

We suggest implementing a call such as "npm run compile-assets" to be able to compile assets when a docker image is built.

Alternatives

Compile assets at runtime

Additional information (if applicable)

I would say this feature fits into several objectives of reducing processing time such as carbon-neutral initiatives or point 12 of the technology code of practice, aiming to make technology sustainable.

Thank you!

frankieroberto commented 12 months ago

This sounds like it’d be something worth investigating to me! 👍

The Heroku documentation for Node.js apps suggests that it will run npm run build automatically before compiling the slug.

If the CSS and javascript assets were compiled by a build step, the source assets themselves could perhaps get added to the .slugignore file, so that the overall slug size is reduced a bit (which can help speed up deploys). That said, most of the CSS and javascript source code is within the govuk-frontend npm package, and that'd still be needed at runtime for all of the macros, so it might not be a huge saving?

smeny commented 12 months ago

The govuk-frontend package has several build scripts that could be invoked. I have been trying to invoke them via npx but without success so far.