title: angular-cli: Conditional Imports using an environment variable
body: <p>Is there a way to conditionally change imports based on an environment variable in angular-cli@1.0.0-beta.16? I'm trying to do it in a way that doesn't require code changes in how services are imported in client code, but when needed I can specify a build flag to swap in mock services.</p>
  
  <p>There is a pattern I tried using from <a href="https://stackoverflow.com/questions/35919878/conditional-import-to-switch-implementations">this post</a>:</p>
  
  <blockquote>
    <p><em>File structure:</em></p>
  
  <pre><code>MyService
      MyServiceMock.ts
      MyServiceReal.ts
      index.ts
  </code></pre>
    
    <p><em>And in your index.ts, you can have the following:</em></p>
  
  <pre><code>import { environment} from '../environments/environment';
  
  export const MyService = environment.mock ?
      require('./MyServiceMock').MyServiceMock:
      require('./MyServiceReal').MyServiceReal;
  </code></pre>
    
    <p><em>And in your client code, import MyService:</em></p>
  
  <pre><code>import MyService from './myservice/index';
  </code></pre>
  </blockquote>
  
  <p>The page loads, and I can see the dependency getting injected when stepping through the code, however there are compilation errors (which I believe are TypeScript errors) along the lines of <code>Cannot find name 'MyService'</code>.</p>