Angular 8 build production with Angular CLI and deploy to IIS server

M
2 min readMar 19, 2020

--

If you are working with the Angular version 8 and your server engine is Window IIS server. Here is an example code for deployment process.

The Angular

Open command line and change directory (cd) to the project

cd ~/<your project name>

Then build the project with Angular-cli

ng build --base-href="/<your sub-directory>/" --prod

with the command line showing above, it will take several minutes in order to processing the code.

After finishing, copy entire files in folder named dist/<your project name>

Then copy to the site directory which located at you Windows server.

The web.config

Create the web.config file with the following chunk of codes

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/<your project sub-directory>/" />
</rule>
</rules>
</rewrite>
<defaultDocument>
<files>
<clear />
<add value="default.aspx" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
<add value="index.php" />
</files>
</defaultDocument>
<staticContent>
<clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
<remove fileExtension=".woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
</staticContent>
</system.webServer>
</configuration>

Done !!!

--

--

M
M

Written by M

Web Developer at Thaibev PLC.

No responses yet