Created
April 3, 2024 21:50
-
-
Save rbrahul/de34b82a40cbd5300e7b85db50d87b9f to your computer and use it in GitHub Desktop.
Generating Multiple File build in Vitejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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