Hey there!
I've been considering whether it's feasible to include a config.json file in a Vue CLI 3 project that can be dynamically read at runtime, both during development and production stages.
This config.json file will hold key strings that the application can utilize to alter content dynamically; for example, changing the video files shown to users or specifying the IP address of a printer.
// config.json
{
"brand": "eat",
"printerIP": "192.168.0.4"
}
I've made attempts to place the file within the assets folder as well as the public folder. I've experimented with importing it into the script lang="ts" part of App.vue using both import and require statements, while also making use of vue-property-decorator.
// App.vue (<script lang="ts">)
const config = require('../public/config.json');
OR
import config from '../public/config.json';
I have extracted the values by treating it like an API through axios, and alternatively simply accessed the variables by referencing them directly, such as config.brand.
// App.vue (<script lang="ts">)
import axios from 'axios';
@Provide() private brand: string = "";
axios
.get('.config.json')
.then(response => {
this.brand = response.data.brand;
})
OR
this.brand = config.brand;
Unfortunately, the data seems to only be accessible at build time and gets compiled into minified JavaScript. Consequently, if a user updates the variables in config.json after the app has been built, the changes won't reflect in the app unless the project is rebuilt. Ideally, I'm looking for a solution where I can modify a value in the build files via config.json and then have the app fetch the updated value at runtime without the need for rebuilding the entire project. Do you think achieving this is possible?
Your assistance on this matter would be truly appreciated.