0

I'm trying to create a file like the appsettings in a web.config in my vue app, that my vue app can use to load config info at runtime that changes form one deployment level to another (dev/qa/prod)

I'm loading it thusly

Vue.prototype.$config = require('/public/config.json')

but when I look at the transpiled output, it has the values of the file loaded in and hardcoded, not code to load from the file

in app90117256.js: (and js.map)

t.exports = JSON.parse('{""name":"value" etc.....

How do I get it to load the file at runtime instead.

1 Answer 1

2

If you want to load the config at runtime, do not use build time constructs, which require or import (or Vue CLI ENV variables) are...

Options:

  1. use either XHR or fetch browser API to request the json file from the server during (or before) your app starts

  2. transform the json into JS file which assigns some global variable (window.appConfig for example), load it using <script> placed in index.html (before your app bundle) and then access it using window.appConfig from the app

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.