Skip to content

[WIP] Rethink frontend bundles #771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

jackdbd
Copy link
Contributor

@jackdbd jackdbd commented Oct 22, 2024

This PR tries to address #770 by generating CSS/JS bundles at build time instead of at runtime.

Warning

At the moment this PR should be considered a work in progress.

Both bundles are generated by esbuild instead of Rollup + Lightning CSS. I have nothing against those tools, but I have more experience with esbuild and I wanted to use esbuild-plugin-manifest to generate a manifest.json to get a mapping of non-hashed asset name => hashed asset name for cache busting.

{
  "public/entries/app.css.map": "public/entries/app-EHISVF66.css.map",
  "public/entries/app.css": "public/entries/app-EHISVF66.css",
  "public/entries/app.js.map": "public/entries/app-VDPQZHVH.js.map",
  "public/entries/app.js": "public/entries/app-VDPQZHVH.js"
}

Also, esbuild can produce a metafile that can be uploaded to Bundle Buddy to visualize the JS bundle.

You can run the following command (from the monorepo root) to generate all bundles and sourcemaps, and compile all nunjucks templates:

npx lerna run build --scope @indiekit/frontend

Then you can launch the "standalone" frontend by serving the public directory using any local web server. For example:

python3 -m http.server --directory packages/frontend/public 8080

@paulrobertlloyd
Copy link
Collaborator

paulrobertlloyd commented Oct 30, 2024

Interesting approach. I was hoping having cached assets would prevent the need to compile assets, but I can see from your issue that this is not the case.

That said, given assets only change between each release, we could:

  • Use a pre-publish script to compile assets and include these in the distributed frontend package,
  • Use Indiekit’s version number for cache-busting.

Ideally the solution would mean we could continue to run a dev server with live asset compilation, while in production pre-built assets would be served instead.

@paulrobertlloyd
Copy link
Collaborator

#776 improved how JavaScript assets are bundled, and #775 moved to a speedier way of generating asset hashes. Things can always be improved of course, but hopefully those changes broadly address this issue, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants