-
Notifications
You must be signed in to change notification settings - Fork 3
Mock settings with Webpack
rleon edited this page Feb 18, 2020
·
1 revision
- Mock the expected /settings.json result. You can use this nodejs code to make a simple mock
- If your mock is published in http://localhost:8000/settings.json, you need to export this var:
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)...