How to load public file before initialization? #3990
Answered
by
brc-dd
ZhongxuYang
asked this question in
Q&A
-
I have a runtime configuration file. It needs to be loaded before the page starts rendering in order for me to use the environment variables inside.(Nav link / Logo / ...) The purpose of this is that when I build the project into a Docker Image, it can be used in multiple places. I only need to modify the Using |
Beta Was this translation helpful? Give feedback.
Answered by
brc-dd
Jun 27, 2024
Replies: 1 comment 3 replies
-
you can just import it inside your config file: // .vitepress/config.ts
import foo from '../public/runtime.json'
export default defineConfig({
// ....
}) you can also use JSON.parse + fs.readFile |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That is likely not possible. VitePress is a "static" site generator. If you want to update the navbar, sidebar, etc. dynamically you'll need to write your own components that fetch runtime.json and generate them on each load. The config file is only loaded during build.