深度优先

这个家伙好懒,除了文章什么都没留下

0%

【Angular】从打包到部署IIS上

以下为打包方式:

通过命令行

1
ng build --prod --aot

会生成dist文件夹,将dist文件夹中的文件,直接上传到服务器IIS站点下。

然后发现可以正常访问,但是刷新页面就会报400错误,这时需要进行如下配置:

1.安装URL rewrite组件:

网址:https://www.microsoft.com/en-us/download/details.aspx?id=47337

2.在该网站目录下添加一个配置文件web.config,复制下边的内容到web.config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?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="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

然后就能正常的访问了!

参考:https://angular.io/guide/deployment#server-configuration