Skip to content
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

[WIP] Rethink frontend bundles #771

Draft
wants to merge 3 commits into
base: main
Choose a base branch
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 paulrobertlloyd force-pushed the main branch 2 times, most recently from 1b91b6e to 69936a4 Compare November 15, 2024 23:40
@paulrobertlloyd paulrobertlloyd force-pushed the main branch 4 times, most recently from 3225b55 to 7934b22 Compare November 26, 2024 01:06
@paulrobertlloyd paulrobertlloyd force-pushed the main branch 2 times, most recently from f8d0cc8 to f877637 Compare December 3, 2024 21:10
@paulrobertlloyd paulrobertlloyd force-pushed the main branch 2 times, most recently from d6ec3d5 to 742898d Compare December 26, 2024 16:40
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