title: How to not compile developer dependencies for production in Angular?
body: <p>I am working on a website which in production will communicate with the back end. The developers use dummy data to test the website during development, but this dummy data is being sent to the client even after a production build. I want to have this dummy data not be included in the final production build to reduce the bundle size.</p>
  
  <p>I have considered using the file replacement feature of the angular compiler to be able to replace a development file with a production variant. I would like to avoid doing this if possible because this feature could be incredibly useful for substituting implementations at compile time without needing to hard code in replacements. Imagine if I had three or four different back end options to choose from and wanted to dynamically pick depending on a setting in my environment service. Once compiled, I would only want to have the one choice present.</p>
  
  <pre><code>@Injectable({
    providedIn: 'root',
    useFactory: () =&gt; {
      const environment = inject(EnvironmentService);
      if (environment.dev) {
        return new DummyDataService();
      }
      return new HttpDataService(inject(HttpClient));
    }
  })
  export abstract class DataService() {
    public abstract getData(): Observable&lt;string[]&gt;;
  }
  </code></pre>
  
  <pre><code>export class HttpDataService implements DataService {
  
    constructor(private http: HttpClient) { }
  
    public getData(): Observable&lt;string[]&gt; {
      return this.http.get&lt;string[]&gt;('/url');
    }
  }
  </code></pre>
  
  <pre><code>export class DummyDataService implements DataService {
  
    public getData(): Observable&lt;string[]&gt; {
      return of([
        'angular',
        'babel',
        'webpack',
        'gulp'
      ]);
    }
  }
  </code></pre>
  
  <p>When I am using 'ng serve --prod' and have configured my environment to run in production. I would expect DummyDataService to not be included in the bundle, but when I inspect what's sent to the browser, DummyDataService is included in the bundle (the name is minified by the compiler, but the strings are still present).</p>