New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(vite): ignore and warn if vite config file exists #21588
fix(vite): ignore and warn if vite config file exists #21588
Conversation
packages/vite/src/vite.ts
Outdated
// https://github.com/vitejs/vite/blob/8fe69524d25d45290179175ba9b9956cbce87a91/packages/vite/src/node/constants.ts#L38 | ||
[ | ||
'vite.config.js', | ||
'vite.config.mjs', | ||
'vite.config.ts', | ||
'vite.config.cjs', | ||
'vite.config.mts', | ||
'vite.config.cts' | ||
].some((fileName) => { | ||
if (existsSync(resolve(nuxt.options.rootDir, fileName))) { | ||
consola.warn(`\`${fileName}\` is not supported. Use \`options.vite\` instead. You can read more in \`https://nuxt.com/docs/api/configuration/nuxt-config#vite\`.`) | ||
return true | ||
} | ||
return false | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we could use Vite's loadConfigFromFile()
instead, but I was not sure how to align its arguments and Nuxt things. π€
Would anyone give me a help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we could use Vite's loadConfigFromFile() instead
I mean, it will return null
if there is no config file found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your approach is more minimal, and the warning is a 'nice-to-have' extra so it is fine if we don't detect an edge case.
You could consider using resolvePath
from mlly
or Nuxt Kit to resolve the config file which might simplify the implementation here.
Should I apply this kind of logic to |
It would be nice if we had a Build section in the docs (similar to the deployment section), that goes more into the details of how the build process works. |
Absolutely, if webpack has the same behaviour. Though I think we could do it in a separate PR. |
π Linked issue
Resolves #21553
β Type of change
π Description
This PR is created based on #21553 (comment).
We can let Vite ignore its config file when calling
build()
andcreateServer()
by settingconfigFile: false
.I tested my logic by adding
vite.config.js
toplayground
directory and runpnpm -w run play:build
to check if the warning message is shown.π Checklist
Should I add some information to docs?