Changing post webpack build configuration values

In the static folder, I have config.js

module.exports = {
  config: {
    urls: {
     auth: localhost
    }
  }
}

I run npm run buildand send the output (dist folder) to the client for deployment in a production environment. I want the client to be able to edit the auth value.

config is currently configured as an external file in webpack:

const config = require(path.join(paths.STATIC, 'config.js'))

externals: [{
    appsetting: JSON.stringify(config)
}]

How do I make config.js recognize changes after building webpack?

+4
source share
2 answers

How about this using axios:

function readConfig () {
   return axios.get('./static/config.js').then((response) => {
       return response.data
   });
}

readConfig().then((config) => {
    // Do stuff
});

And make sure config.js is copied to the static / folder.

+1
source

Create a login file in webpack.config for config.jsand import / require config.jsinto other files in which you use the configuration.

0

Source: https://habr.com/ru/post/1690707/


All Articles