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

Support bundling HTML files and their js, css, and assets in Bun.build and bun build #15940

Merged
merged 24 commits into from
Dec 23, 2024

Conversation

Jarred-Sumner
Copy link
Collaborator

@Jarred-Sumner Jarred-Sumner commented Dec 22, 2024

What does this PR do?

Fixes #4688

This lets you bundle HTML files in Bun. It uses lol-html to parse and enqueue assets.

Currently, elements matching the following selectors are considered for either bundling (if js/css) or copied when non-external:

  • script[src]
  • link[rel='stylesheet'][href]
  • link[as='style'][href]
  • link[as='font'][href], link[type^='font/'][href]
  • link[as='image'][href]
  • link[as='video'][href], link[as='audio'][href]
  • link[as='worker'][href]
  • link[rel='manifest'][href]
  • link[rel='icon'][href], link[rel='apple-touch-icon'][href]
  • link:not([rel~='stylesheet']):not([rel~='modulepreload']):not([rel~='manifest']):not([rel~='icon']):not([rel~='apple-touch-icon'])[href]
  • img[src]
  • img[srcset]
  • video[src]
  • video[poster]
  • audio[src]
  • source[src]
  • source[srcset]
  • iframe[src]

This list will probably change before this merges. It should probably be configurable.

How did you verify your code works?

There are tests.

@robobun
Copy link

robobun commented Dec 22, 2024

Updated 10:09 AM PT - Dec 23rd, 2024

@Jarred-Sumner, your commit 806c4b2 has passed in #8460! 🎉


🧪   try this PR locally:

bunx bun-pr 15940

@Jarred-Sumner Jarred-Sumner marked this pull request as ready for review December 22, 2024 15:08
Copy link
Member

@paperdave paperdave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall legendary pr. very nice to have this.

random nitpicks and two that should be considered before merging. the main logic looks fine

src/bake/DevServer.zig Outdated Show resolved Hide resolved
src/bundler/bundle_v2.zig Outdated Show resolved Hide resolved
// a <link rel="modulepreload" href="..." crossorigin> tag that
// points to the module or chunk's unique key so that we tell the
// browser to preload the user's code.
// We might also want to force <!DOCTYPE html> at the top of the file, but I'm not sure about that yet.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its fine to take no action re:doctype

the one person who wants to bundle quirks mode html can do so

src/bundler/bundle_v2.zig Outdated Show resolved Hide resolved
src/html_scanner.zig Outdated Show resolved Hide resolved
src/html_scanner.zig Outdated Show resolved Hide resolved
test/bundler/bundler_html.test.ts Show resolved Hide resolved
@ohroy
Copy link

ohroy commented Dec 23, 2024

awesome !!! but would you fix #5241 ? this block we switch to bun build

@Jarred-Sumner Jarred-Sumner merged commit da54e81 into main Dec 23, 2024
67 checks passed
@Jarred-Sumner Jarred-Sumner deleted the jarred/html-load branch December 23, 2024 19:04
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.

Support index.html as an entrypoint
4 participants