D
D
Dmitry2020-10-26 21:03:10
Vue.js
Dmitry, 2020-10-26 21:03:10

How to organize a default settings file for your Vue app?

It is required in the production version (in the dist folder, compiled by the standard vue-cli) to have a file with settings that the user can easily change and the whole application will work with the new settings.

For example, I tried to create a settings.js file in the public folder:

export const settings = {
  vizEngineIp: '127.0.0.1:61000',
  jsonServerIp: '127.0.0.1:3000',
}


And I import it in the main Vue component: But this way all the settings are baked into the output js. What is the best way to organize a static js file (or json) that will not be baked into the application code, but will remain independent and easy to edit?
import { settings } from '../public/settings.js'


Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey delphinpro, 2020-10-26
@svetozar

Place the json file in the public folder. Pure json with settings, without any exports.
When the application loads the first page (for example, in the created hook of the App component), it loads this file and applies settings from it.

A
Alexey Yarkov, 2020-10-26
@yarkov Vue.js

Write your settings to a global variable and, when building, take out your settings as a separate chunk and connect them before the application script.
Then it will be possible to pick up changes on the fly.

D
Dmitry, 2020-10-26
@By_Engine

No way. Either use backend or store settings in localstorage

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question