I have a Vue3/Vite project where some data has to be read from an external JSON file.
but when i build the project - the JSON file gets bundled.
I need to keep the JSON file external.
What I've tried:
- first try
vite.config.ts
export default defineConfig({
optimizeDeps:{
exclude: ['myfile.json'] // then i tried ['**/myfile.json']
},
})
- second try
vite.config.ts
assetsInclude: ['**/*.json'],
assetsInlineLimit: 0,
- third try
App.vue
let jsonData = import.meta.glob('/public/assets/myfile.json')
What am I doing wrong - is there a simple way to keep a JSON file external?
CodePudding user response:
Nvm, in Vite you directly use fetch
to grab the data rather than import
.
file.json
being
{
"name": "bob",
"age": 29
}
And with the following result