如何在iis上部署angular-cli app [英] How to deploy angular-cli app on iis

查看:223
本文介绍了如何在iis上部署angular-cli app的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的angular2-cli应用程序(一页有模型驱动形式 - 不涉及路由器)。 ng serve一切正常。我用ng build --product制作了生产版本。我将所有./dist文件夹内容复制到C:\inetpub \ www.root下的新文件夹中。我从IIS管理控制台制作了虚拟应用程序。 Defualt应用程序文件是index.html。我浏览到app uri,我只得到正在加载...的页面。我试着没有--product switch(只有ng build),但结果是一样的。角度应用程序未加载。还有什么需要在IIS上发布角度应用程序吗?

I have simple angular2-cli app (one page with model driven form - no router involved). With "ng serve" all works fine. I made production version with ng build --product. I copied all ./dist folder content into new folder under C:\inetpub\wwwroot. I made virtual app from IIS managment console. Defualt app file is index.html. I browse to app uri and i get only page with "Loading...". I try build without --product switch (only ng build) but result is the same. Angular app is not loading. Is there anything else needed to publish angular app on IIS?

推荐答案

以下是我解决这种情况的方法;

Here is how I solve this situation;


  • 使用angular-cli创建项目

  • 使用 ng build

  • 打开IIS,创建新的虚拟目录并显示 dist 文件夹

  • 设置index.html中的 base href / / yourAliasNameOnIIS

  • 使用此web.config将请求重定向到index.html页面

  • Create project with angular-cli
  • Build your application with ng build
  • Open IIS, create new virtual directory and show dist folder
  • Set base href in your index.html from / to /yourAliasNameOnIIS
  • Use this web.config for redirecting requests to your index.html page

<system.webServer>
<rewrite>
  <rules>
    <rule name="AngularJS Routes" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
      </conditions>
      <action type="Rewrite" url="/yourAliasNameOnIIS" />
    </rule>
  </rules>
</rewrite>

转换虚拟目录到Web应用程序

Convert your virtual directory to a web application

您还可以使用 ng build --deploy-url / yourAliasNameOnIIS更改 dist / index.html 中的src路径。

You can also use ng build --deploy-url "/yourAliasNameOnIIS" to change src path in dist/index.html.

I希望它有所帮助!

这篇关于如何在iis上部署angular-cli app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆