Skip to content

Instantly share code, notes, and snippets.

@cecilemuller
Created April 4, 2024 15:51
Show Gist options
  • Save cecilemuller/2e514c253d92cd3ecfd3645c5f9fdbc0 to your computer and use it in GitHub Desktop.
Save cecilemuller/2e514c253d92cd3ecfd3645c5f9fdbc0 to your computer and use it in GitHub Desktop.
Vite: multiple entries, independant output paths
/* eslint-env node */
import {fileURLToPath} from "node:url";
/**
* @returns {import("vite").PluginOption}
*/
function buildPlugin(pages) {
return {
name: "change-html-output",
enforce: "post",
config: () => ({
build: {
rollupOptions: {
input: Object.keys(pages).map((url) => fileURLToPath(new URL(url, import.meta.url)))
}
}
}),
generateBundle(_options, bundle) {
for (const url in pages) {
if (url in bundle) {
bundle[url].fileName = pages[url];
}
}
}
};
}
/** @type {import("vite").UserConfigFnObject} */
export default (/* { command, mode, isSsrBuild, isPreview } */) => {
return {
build: {
target: "es2022",
modulePreload: false,
},
plugins: [
buildPlugin({
"tmp/00.html": "arbitrary/output/index-00.html",
"tmp/01.html": "index-01.html",
"tmp/02.html": "hello/world-02.html",
})
]
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment