Skip to content

stop moving script tag into the body - html rollup plugin #2995

Open

Description

@ecofi

The rollup html plugin moves some scripts tags into the body tag of html document. How can this be prevented/stopped?

Furthermore, this should not be default setting to move script tags into html body.

Activity

  1. bashmish commented on Dec 24, 2025

    @bashmish
    Member

    Can you please provide a test reproducing this problem or pinpoint existing one that illustrates it?

  2. ecofi commented on Dec 24, 2025

    @ecofi
    Author

    Sure, see below

    test.html

    <html>
        <head>
            <script type="module" src="./test.mjs"></script>
        </head>
        <body>
            
        </body>
    </html>
    

    test.mjs

    document.body.textContent = "Test";

    rollup.config.mjs

    import { rollupPluginHTML as html } from "@web/rollup-plugin-html";
    
    export default {
      input: "test.html",
      output: { dir: "dist" },
      plugins: [
        html({
          extractAssets: false,
        }),
      ],
    };
    

    after running command rollup --config ./rollup.config.mjs

    the converted test.html in dir dist has this content where script tag moved inside the body tag

    <html>
    <head></head>
        <body><script type="module" src="./test.js"></script></body>
    </html>
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions