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

When minifying HTML, Bun removes tags in head #17124

Closed
The-Best-Codes opened this issue Feb 6, 2025 · 1 comment
Closed

When minifying HTML, Bun removes tags in head #17124

The-Best-Codes opened this issue Feb 6, 2025 · 1 comment
Assignees
Labels
bug Something isn't working bundler Something to do with the bundler needs triage

Comments

@The-Best-Codes
Copy link

What version of Bun is running?

1.2.2

What platform is your computer?

Linux 6.11.0-14-generic x86_64 x86_64

What steps can reproduce the bug?

Start with an HTML file like this one:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="A simple HTML page with meta tags">
    <meta name="author" content="Your Name">
    <meta name="keywords" content="HTML, meta tags, simple page">
    <title>Simple HTML Page</title>
</head>
<body>
    <h1>Welcome to My Simple Page</h1>
    <p>This is a basic HTML page with essential meta tags.</p>
</body>
</html>

Run this command (which works):

bun build index.html --outdir dist

The HTML output should be:

HTML code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="A simple HTML page with meta tags">
    <meta name="author" content="Your Name">
    <meta name="keywords" content="HTML, meta tags, simple page">
    <title>Simple HTML Page</title>
<script type="module" crossorigin src="./index-[hash].js"></script></head>
<body>
    <h1>Welcome to My Simple Page</h1>
    <p>This is a basic HTML page with essential meta tags.</p>
</body>
</html>

Now run this command instead, which does not work:

bun build index.html --outdir dist --minify

The HTML file will now look like:

<!DOCTYPE html>
<html lang="en">
<head><script type="module" crossorigin src="./index-[hash].js"></script></head>
<body>
    <h1>Welcome to My Simple Page</h1>
    <p>This is a basic HTML page with essential meta tags.</p>
</body>
</html>

Notice that the <meta> tags and <title> are missing.
I have a suspicion that when minifying, Bun just includes the scripts and CSS in the head, erasing everything else.

What is the expected behavior?

The minified HTML output should include other tags in <head>, like this:

HTML code

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="description" content="A simple HTML page with meta tags"><meta name="author" content="Your Name"> <meta name="keywords" content="HTML, meta tags, simple page"><title>Simple HTML Page</title><script type="module" crossorigin src="./index-y1e0g89h.js"></script></head>
<body>
    <h1>Welcome to My Simple Page</h1>
    <p>This is a basic HTML page with essential meta tags.</p>
</body>
</html>

What do you see instead?

Missing tags in <head>.

Additional information

No response

@The-Best-Codes The-Best-Codes added bug Something isn't working needs triage labels Feb 6, 2025
@paperclover paperclover added the bundler Something to do with the bundler label Feb 6, 2025
@paperclover
Copy link
Member

this will be fixed in #16955

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bundler Something to do with the bundler needs triage
Projects
None yet
Development

No branches or pull requests

2 participants