I have a svelte project (not sveltekit) that is being built/bundled by vite.
The problem I am having is that the build times are growing unwieldly. Most of the time this project is being built without any changes to it (part of a bigger project), but it still builds for ~10 seconds, which makes me think that it is not doing any caching at all.
So my question is: is it possible to enable a build cache for vite?
And as a side thing: if I am building with the watch flag, each save triggers a full rebuild. Is it possible to only partially rebuild the code to speed things up?
my config currently looks like this
export default defineConfig({
resolve: {
alias: {
"$lib": __dirname + "/src/svelte/lib",
"$logo": __dirname + "/src/LogoTool",
}
},
plugins: [svelte(), i18n()],
build: {
cssMinify: 'lightningcss',
rollupOptions: {
cache: true,
output: {
entryFileNames: `assets/[name].js`,
chunkFileNames: `assets/[name].js`,
assetFileNames: `assets/[name].[ext]`
}
},
lib: {
entry: "./src/svelte/main.ts",
formats: ["umd"],
name: "svelte"
},
minify: 'terser',
terserOptions: {
compress: true,
mangle: true,
keep_classnames: false,
ie8: false
},
},
publicDir: "assets",
server: {
}
})
You are not meant to do a regular build on change, use the dev server instead (vite dev
).
It compiles only the necessary files and does not do any costly post-processing (minification, de-duping, etc.). Changed files are updated in place via hot module replacement (no page reload required unless state is out of sync).
See the backend integration docs, if the rest of your application/page needs to be served separately.