We are upgrading out entire app to Webpack 2.x React 16.x, etc from versions that are 3 years old. So far spent 2 full months coding and still not done. However, yesterday was the first day we were going to actually deploy to our dev servers. However, we have an issue in our build. When running locally on dev machines we don't do any string replacements. But on other machines we have to change the server URL the UI points to. And this is where we use String replace plugin. On the command line we used to pass --dev or --prod to state the environment which would be used to replace the Server URL in our files. However, Webpack 2.0 changed it to where you can't just send arbitrary command line args like --dev, instead you have to pass --env.dev or --env.prod. However, I can't figure out how to access that from within our function for String replace. Here is our environment.js
`let environment = null;
function backendURL(match, p1, offset, string) {
if (environment.production) {
return PRD_SERVER;
} else if (environment.stage) {
return STAGE_SERVER;
} else if (environment.conv) {
return CONV_SERVER;
} else if (environment.test) {
return TST_SERVER;
} else if (environment.dev) {
return DEV_SERVER;
} else {
return LOCAL_SERVER;
}
}
We are upgrading out entire app to Webpack 2.x React 16.x, etc from versions that are 3 years old. So far spent 2 full months coding and still not done. However, yesterday was the first day we were going to actually deploy to our dev servers. However, we have an issue in our build. When running locally on dev machines we don't do any string replacements. But on other machines we have to change the server URL the UI points to. And this is where we use String replace plugin. On the command line we used to pass --dev or --prod to state the environment which would be used to replace the Server URL in our files. However, Webpack 2.0 changed it to where you can't just send arbitrary command line args like --dev, instead you have to pass --env.dev or --env.prod. However, I can't figure out how to access that from within our function for String replace. Here is our environment.js
`let environment = null;
function backendURL(match, p1, offset, string) { if (environment.production) { return PRD_SERVER; } else if (environment.stage) { return STAGE_SERVER; } else if (environment.conv) { return CONV_SERVER; } else if (environment.test) { return TST_SERVER; } else if (environment.dev) { return DEV_SERVER; } else { return LOCAL_SERVER; } }
module.exports = function(env) { environment = env; getBackendURL: backendURL };`
And here is our module loader
{ test: /js\/constants.js$/, loader: StringReplacePlugin.replace({ replacements: [{ pattern: /localhost/g, replacement: Environment.getBackendURL }] }) }
That doesn't seem to work. Thanks for any help you can provide. My Google search wasn't very successful.
Mark