【发布时间】:2012-10-24 04:58:42
【问题描述】:
我希望我的 IIS 正确显示 .ts 文件,TypeScript 是否有任何 MIME 类型? text/javascript 或类似的也可以工作,但有规范吗?
我已经查过language specification,但没有找到任何线索。
【问题讨论】:
标签: mime-types typescript
我希望我的 IIS 正确显示 .ts 文件,TypeScript 是否有任何 MIME 类型? text/javascript 或类似的也可以工作,但有规范吗?
我已经查过language specification,但没有找到任何线索。
【问题讨论】:
标签: mime-types typescript
最好知道为什么您要提供 TypeScript 文件。
据我了解,TypeScript 用于编译成 Javascript,然后在浏览器中执行。目前,没有对 TypeScript 的原生支持(如果我错了,请纠正我)。
如果您仍想通过 IIS 提供 .ts 文件,您仍然可以在与 .ts 关联的 IIS Admin 中添加custom mime-type。该标准定义了前缀x.、vnd. 和prs.,以及vnd。前缀也列在标准化的 mime 类型 text/ 和 application/ 中。
因此,根据您的使用情况,您可以选择text/x.typescript 或text/prs.typescript。
【讨论】:
x. 已被弃用,有利于区分 prs.(“我自己需要一个 mime 类型”)和 vnd.(“我需要一个 mime 类型在我的组织下发布树")
将此粘贴在您的 web.config 中;
<configuration>
...
<system.webServer>
<staticContent>
<mimeMap fileExtension=".ts" mimeType="application/x-typescript" />
</staticContent>
</system.webServer>
</configuration>
【讨论】:
Deno 使用 application/typescript 提供 TypeScript 文件,允许您运行它们:
deno run "https://example.com/file.ts"
【讨论】:
您可能还需要注释掉将 .ts 文件转换为 javascript 的 TypeScriptAssetHandler。
<handlers>
<!--<add name="TypeScriptAssetHandler" path="*.ts" verb="GET" type="BundleTransformer.TypeScript.HttpHandlers.TypeScriptAssetHandler, BundleTransformer.TypeScript" resourceType="File" preCondition="" />-->
</handlers>
如果你定义了这个处理程序,你最终可能会遇到这样的错误
[HttpException (0x80004005): During the output text content of processed asset an unknown error has occurred.
See more details:
Exception has been thrown by the target of an invocation.]
【讨论】:
使用 Apache 2,我只需将 MIME 类型设置为 text/plain。这解决了我得到奇怪结果的问题,因为报告的 MIME 类型是某种视频格式。
您可以在 Apache 2 配置中通过以下方式实现此目的:
<filesMatch "\.(html|htm|js|css|ts|ts!transpiled)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>
AddType text/plain ts
【讨论】: