Angular部署到windows上

1. 确保已经打开了IIS服务。html

  若是没有打开可参考 http://jingyan.baidu.com/article/eb9f7b6d9e73d1869364e8d8.htmlweb

2. 编译angular程序  ng build --prod --aot.网站

   编译后项目中会出现dist文件夹ui

3. 在IIS中添加网站url

 

4. 将编译后的dist文件夹添加到网站中spa

 

 

5. 安装URL Rewrite Module3d

因為Angular無刷新的特性,因此瀏覽器地址欄上的網址其實不會真實映射到磁盤的特定位置,因此我們须要安裝xml

下载地址: https://www.microsoft.com/en-us/download/details.aspx?id=47337 <https://www.microsoft.com/en-us/download/details.aspx?id=47337>htm

6. 新建web.config文件。内容以下blog

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="AngularJS" 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="/project" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

 

7. 若是项目中有资源文件 须要将资源文件拷入到dist中

 

8. 设置dist文件夹的权限 最简单的能够设置为如下

 

 

 

*转载请附出处