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
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.