Skip to content

fix(schema,vite): respect vite.cacheDir if defined#27628

Merged
danielroe merged 6 commits intonuxt:mainfrom
jdbdnz:main
Jun 15, 2024
Merged

fix(schema,vite): respect vite.cacheDir if defined#27628
danielroe merged 6 commits intonuxt:mainfrom
jdbdnz:main

Conversation

@jdbdnz
Copy link
Copy Markdown
Contributor

@jdbdnz jdbdnz commented Jun 15, 2024

🔗 Linked issue

#27627

📚 Description

Vite's shared option cacheDir is not currently supported by vite-builder. This PR allows setting it in Nuxt config vite object.

# nuxt.config.js

export default defineNuxtConfig({
  ...
  vite: {
    cacheDir: "node_modules/.cache/vite_custom"
  }
}

🤨 Why

I am running instances of nuxt dev simultaneously in one directory. When they both target the same vite.cacheDir there are conflicts and unexpected behaviors ensue (mostly, app doesn't load).

😌 QA

Modified in Playground to confirm it modified Vite's cache directory.

image

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@dash-
Copy link
Copy Markdown

dash- commented Jun 15, 2024

I'd love to see this merged. I could finally get rid of the dirty hacks I'm doing to avoid the same issue.

@danielroe
Copy link
Copy Markdown
Member

danielroe commented Jun 15, 2024

This seems good to me. Only - I wonder if we could do it automatically. I assume you also have a custom buildDir, right?

Maybe we could use a hash of that path to create a folder like node_modules/.cache/vite-<hash>...

Obviously it would still be configurable, but the default value would mean no additional config was required if you already customised your buildDir.

I'm thinking of this also with #14607 in mind - I wouldn't want to break your setup again when that is implemented.

@danielroe danielroe changed the title feat: use vite uses ctx.config.cacheDir if defined fix(schema,vite): respect vite.cacheDir if defined Jun 15, 2024
@danielroe danielroe merged commit 88f0b4f into nuxt:main Jun 15, 2024
@github-actions github-actions bot mentioned this pull request Jun 15, 2024
@dash-
Copy link
Copy Markdown

dash- commented Jun 20, 2024

Great to see this. An overridable default that works automatically when different build directories exist (using hashes of the build directories) also makes sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants