无法 运行 IIS 中的 Angular2 应用程序
Unable to run the Angular2 app in IIS
我遵循 Angular2 Quick start example 并使用 live-server 到 运行 它。效果很好。
然后我在 IIS 中创建了一个 网站 并将虚拟目录设置为我拥有 index.html 的目录文件。当我 运行 网站时,出现以下错误。当 IIS 尝试服务器 app.ts.
时发生错误
如何在 IIS 中 运行 Angular2 应用程序?
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
更新:
解决方法:我新建了一个web.config文件,添加了下面的代码片段来添加MIME类型。这将被 IIS 用作本地网络应用程序设置。
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".ts" mimeType="application/x-typescript" />
</staticContent>
</system.webServer>
</configuration>
尝试注册 .ts mime 类型
此外,this SO 似乎是一个很好的解释
按照惯例,不建议直接提供 TypeScript (.ts) 文件。这就是默认情况下 IIS 不启用此功能的原因。快速入门教程还在页面的中途明确提到了这一点,在 这有什么问题? 部分,其中说明如下:
We were up and running in a hurry and we could explore Angular in this manner for quite some time. For a number of reasons this isn't a good approach for building an application:
- Transpiling TypeScript in the browser becomes tediously slow when our app grows beyond a few files. We certainly won't do that in production. We should learn to compile locally and push the generated JavaScript to the server. We'll need some tools for that.
因此,如果您再多花几分钟完成本教程,它会很好地满足您的需求,而无需费心进行 IIS 配置。
也就是说,如果您真的想要它,是可能的。正如其他评论中提到的,您可以在 IIS 中为 .ts
文件添加 MIME 类型。在 SO 问题 What's the MIME-Type of TypeScript 中也有解释。
我遵循 Angular2 Quick start example 并使用 live-server 到 运行 它。效果很好。
然后我在 IIS 中创建了一个 网站 并将虚拟目录设置为我拥有 index.html 的目录文件。当我 运行 网站时,出现以下错误。当 IIS 尝试服务器 app.ts.
时发生错误如何在 IIS 中 运行 Angular2 应用程序?
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
更新:
解决方法:我新建了一个web.config文件,添加了下面的代码片段来添加MIME类型。这将被 IIS 用作本地网络应用程序设置。
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".ts" mimeType="application/x-typescript" />
</staticContent>
</system.webServer>
</configuration>
尝试注册 .ts mime 类型
此外,this SO 似乎是一个很好的解释
按照惯例,不建议直接提供 TypeScript (.ts) 文件。这就是默认情况下 IIS 不启用此功能的原因。快速入门教程还在页面的中途明确提到了这一点,在 这有什么问题? 部分,其中说明如下:
We were up and running in a hurry and we could explore Angular in this manner for quite some time. For a number of reasons this isn't a good approach for building an application:
- Transpiling TypeScript in the browser becomes tediously slow when our app grows beyond a few files. We certainly won't do that in production. We should learn to compile locally and push the generated JavaScript to the server. We'll need some tools for that.
因此,如果您再多花几分钟完成本教程,它会很好地满足您的需求,而无需费心进行 IIS 配置。
也就是说,如果您真的想要它,是可能的。正如其他评论中提到的,您可以在 IIS 中为 .ts
文件添加 MIME 类型。在 SO 问题 What's the MIME-Type of TypeScript 中也有解释。