title: How to force Angular cli to serve the bundle files from an absolute location rather then base-href
body: <p>I'm struggling with deploying Angular 4 project built with cli to a Spring boot server.</p>
  
  <p>In the <strong>.angular-cli.json</strong> I added outdir property, which points to a custom folder inside Spring webapp folder, which is accessible directly in the server (webapp/main).</p>
  
  <p>The cli build command I'm using is: </p>
  
  <pre><code>ng build --base-href /main/ -a main
  </code></pre>
  
  <p>Which creates the main folder in the webapp, with the index.html containing the following script tags:</p>
  
  <pre><code>&lt;base href="/main/"&gt;
  ...
  &lt;script type="text/javascript" src="inline.bundle.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="polyfills.bundle.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="vendor.bundle.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="main.bundle.js"&gt;&lt;/script&gt;&lt;/body&gt;
  </code></pre>
  
  <p>which means that these files will be requested with /main prefix, e.g <strong>localhost:8080/main/inline.bundle.js</strong></p>
  
  <p>Which is fine for a basic app, but becomes an issue when routes are added to the angular app (In Spring, I'm serving the index.html for all paths with /main, to allow the angular routes to work properly, which cause a redirect loop for the bundles, <strong>as they are starting with /main as well</strong>.</p>
  
  <p><strong>How can I force the generated script tags to use a custom location?</strong> Or at least specifiy the absolute location, and not relay on the base href (so I can change the outDir property to main-app, and problem solved).</p>
  
  <p>The desired solution would be something like this:</p>
  
  <pre><code>&lt;script type="text/javascript" src="/main-app/main.bundle.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>I thought of maybe adding a script that will execute after the ng build which will modify the script tags, but it's a dirty solution, and also won't work with <strong>ng build --watch</strong>, which is crucial for development... </p>
  
  <p>For reference, here is the Spring controller function that maps the /main requests:</p>
  
  <pre><code>@RequestMapping("main/**")
  public String mainRoute(HttpServletRequest request) {
         return "/main/index.html";
  }
  </code></pre>
  
  <p>Thanks!</p>