Skip to content

Instantly share code, notes, and snippets.

@cecilemuller
Last active April 2, 2024 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cecilemuller/b2135b66d0f917101da5ed3a5a208b15 to your computer and use it in GitHub Desktop.
Save cecilemuller/b2135b66d0f917101da5ed3a5a208b15 to your computer and use it in GitHub Desktop.
Vite generates en empty script when `build.rollupOptions.input` is set

Merely setting build.rollupOptions.input forces a script to be generated even if the page has none (whereas the default behavior doesn't generate the empty js file):

vite.config.js points to the same default location:

export default {
    build: {
        rollupOptions: {
            input: "index.html"
        }
    }
};

index.html contains no script nor styles:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>
<body>Hello World</body>
</html>

Yet vite build generates an empty asset if input is set (remove the line in the config to see the difference):

vite v5.2.7 building for production...
✓ 1 modules transformed.
dist/index.html                0.13 kB │ gzip: 0.12 kB
dist/assets/index-l0sNRNKZ.js  0.00 kB │ gzip: 0.02 kB
@cecilemuller
Copy link
Author

Interesting additional data point: using the absolute path such as input: resolve(__dirname, "index.html") prevents generating the empty asset, despite processing appears to be the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment