Using Vite and Vue, I want to get a single JavaScript file without generating an assets
folder containing SVG and GIF files when I run the build (without copying the SVG code and pasting it in a Vue JS file as a placeholder).
Is there is a way to do that? I have been searching for a day but I didn't find any answers. Any help is appreciated. However GIFs seem to be automatically inlined.
Assuming you are running Vite version 5, you could consider setting a high number for the build.assetsInlineLimit
option:
Imported or referenced assets that are smaller than this threshold will be inlined as base64 URLs to avoid extra http requests.
SVGs and GIFs are considered assets and thus setting this option to a large number should inline most assets. Vite 5 is needed for this to work as SVG inline was only introduced in this version.
/* vite.config.js */
import { defineConfig } from 'vite';
export default defineConfig({
build: {
assetsInlineLimit: Number.MAX_SAFE_INTEGER,
},
});