title: Can I pass a variable to environment.ts on ng serve?
body: <p>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 <code>connectToBackend=true</code>.</p>
  <pre class="lang-js prettyprint-override"><code>// 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,
  };
  </code></pre>
  <p>How can I make <code>connectToBackend</code> a dynamic variable that is set by the command line when serving the project? For example:</p>
  <pre><code>ng serve --connectToBackend=true
  </code></pre>