Skip to content

Instantly share code, notes, and snippets.

@rbrahul
Created April 3, 2024 21:50
Show Gist options
  • Save rbrahul/de34b82a40cbd5300e7b85db50d87b9f to your computer and use it in GitHub Desktop.
Save rbrahul/de34b82a40cbd5300e7b85db50d87b9f to your computer and use it in GitHub Desktop.
Generating Multiple File build in Vitejs
import { defineConfig } from "vite";
function getDirFromAsset(assetInfo) {
if(!assetInfo.name){
return "assets"
}
else if (assetInfo.name.endsWith("css")) {
return "css";
} else if (assetInfo.name.endsWith("js")) {
return "js";
}
return "assets";
}
const inputs = {
background: "src/js/background.js",
editor: "src/js/editor.js",
};
export default defineConfig({
build: {
manifest: true,
rollupOptions: {
input: inputs,
output: {
assetFileNames: (assetInfo) => {
const dir = getDirFromAsset(assetInfo);
return `${dir}/[name].[hash].[ext]`;
},
entryFileNames: `js/[name].[hash].js`,
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment