Skip to content

Mock settings with Webpack

rleon edited this page Feb 18, 2020 · 1 revision

Mock /settings.json with webpack

export DEV_SETTINGS_URL=http://localhost:8000/settings.json
  • Add this var in the webpack of your project(react, vue, angular, jquery, etc):
plugins: [
  new webpack.DefinePlugin({
    DEV_SETTINGS_URL: JSON.stringify(process.env.DEV_SETTINGS_URL)
  })
]
  • That's all. You can use this var in your code:
if(DEV_SETTINGS_URL != null){
  SETTINGS_URL=DEV_SETTINGS_URL;
}
else{
  var urlHelper = new microfrontendTools.UrlHelper();
  var domain = urlHelper.getLocationBasePath();
  SETTINGS_URL=domain+"/settings.json";
}...

And use it with axios for example:

axios.get(SETTINGS_URL).then(response => response.data)...
Clone this wiki locally