Tailwind Memory Spike with Tauri with Vue with Vite in Dev Mode #20439
Replies: 6 comments 1 reply
|
I think this is source detection rather than utilities generation, and the way you isolated it is the strongest clue. If you look in Two minute check. Pin the sources explicitly and see if it goes away: @import "tailwindcss" source(none);
@source "./src";If memory returns to normal, it is automatic source detection, and the fix is to keep that or exclude whatever tree is being walked. If it does not change, then it is something else, and that is worth saying here too. For a Tauri project specifically, check whether anything large sits outside your ignore rules. Measurements. Minimal Vite plus Tailwind project with one large un-ignored directory (1500 files, about 22 MB). Tailwind 4.3.3, Vite 6.3.5, Node 22, Linux x64, peak RSS of
Same shape on 4.1.7 (1331 MB against 177 MB). Cold and warm Vite caches measured the same, 1331 and 1344 MB, so this is not dependency pre-bundling. One thing I could not explain, in case it helps whoever picks this up. An explicit The repro is small if it is useful, happy to post it. |
|
Before you chase WebKitGTK, please check one thing, because I think I sent you down a wrong path and the numbers above may not mean what they look like.
So with Quick way to tell which you measured: build, then grep the emitted CSS for a class you actually use. grep -c '^\s*\.flex' dist/assets/*.css # or any utility you know is in your markupZero means the source set is empty and the page is unstyled, which would also show visually. You did mention trying One thing that would separate the two cleanly, since you already have the comparison set up: build once with the working Sorry for the detour. The relative-path behaviour is easy to miss and I should have flagged it when I suggested the line. |
|
The split imports provide a useful diagnostic, but the source directive must be attached to the utilities import and every explicit For a stylesheet at @layer theme, base, components, utilities;
@import "tailwindcss/theme.css" layer(theme);
@import "tailwindcss/preflight.css" layer(base);
@import "tailwindcss/utilities.css" layer(utilities) source(none);
@source "./";Here I would compare three facts for each run:
If Tailwind documents both the stylesheet-relative rule and Since this is a Tauri repository, also make sure generated directories such as |
Install: pnpm add -D @tailwindcss/postcss postcss Add to postcss.config.js: export default { Remove @tailwindcss/vite from vite.config.ts.
@import "tailwindcss"; |
|
@CyberNeo1337 Since you are using Vite + Tauri + WebKitGTK, this memory behavior is caused by a double-invalidation feedback loop between Vite's HMR file watcher and WebKitGTK's dev inspector. Here is the exact breakdown of why this happens and how to permanently resolve it:
Applying the |
Why this happensIn a Tauri application, the Rust backend lives inside the By default, Tailwind v4's automatic source scanner and Vite's file watcher attempt to index the entire project workspace. Crawling through the heavy Cargo build directory consumes a huge amount of memory and causes severe dev-server memory spikes. How to Fix1. Pin your CSS source explicitlyTurn off automatic workspace scanning in Tailwind v4 and point it exclusively at your frontend source directory: @import "tailwindcss" source(none);
@source "./src";2. Exclude src-tauri in vite.config.tsPrevent Vite's file watcher from inspecting the Tauri backend and Cargo cache: import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
plugins: [vue()],
server: {
watch: {
ignored: ['**/src-tauri/**']
}
}
});Restart your Vite dev server after updating the config, and memory usage will return to normal. |
Uh oh!
There was an error while loading. Please reload this page.
All reactions