I'm regularly running a project locally with two different configurations. One with stubbed data, one connected to the Spring Boot backend. I can switch between these modes with the below logic by making connectToBackend=true
.
// Angular 11, src/environments/environment.ts
import processStubs from '[REDACTED]';
import processBackend from '[REDACTED]';
import { Launcher } from '[REDACTED]';
let connectToBackend = false;
let processLocal;
if (connectToBackend) {
processLocal = processBackend;
} else {
processLocal = processStubs;
}
export const environment = {
process: processLocal,
launcher: Launcher,
production: false,
backendConnection: connectToBackend,
};
How can I make connectToBackend
a dynamic variable that is set by the command line when serving the project? For example:
ng serve --connectToBackend=true