-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Allow accessing Vite mode from config.ts
#4183
Comments
You can use env variables as a workaround: // MODE=foo vitepress dev docs
const mode = process.env.MODE || 'default' |
@brc-dd Is is possible to load a different CSS depending on the I am trying from import DefaultTheme from 'vitepress/theme'
const mode = import.meta.env.MODE || 'blue'
import(`./style-${mode}.css`)
export default DefaultTheme Which works for development, but for building, it seems like both:
Would yield the same result. |
Replying to my own question, in case this is useful for someone else, you can use in return defineConfig({
vite: {
define: {
'process.env.MODE': JSON.stringify(mode),
},
},
} And in import DefaultTheme from 'vitepress/theme'
const mode = process.env.MODE
import(`./style-${mode}.css`)
export default DefaultTheme |
Ah, you need to prefix it with
|
Related to this: #4222. Opened a separate issue since it is independent (i.e.: allow accesing Vite mode from |
Is your feature request related to a problem? Please describe.
With Vite, I can access the
--mode
flag with:With Vitepress, however, this does not seem to be possible, since this command always results in
mode == "development"
:Describe the solution you'd like
Executing this command:
Should make this code pass:
Describe alternatives you've considered
Haven't found a suitable alternative. Are there any?
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: