source

TypeScript의 MIME-Type은 무엇입니까?

factcode 2023. 7. 8. 11:13
반응형

TypeScript의 MIME-Type은 무엇입니까?

IIS가 .ts 파일을 올바르게 표시하기를 원하는데, TypeScript용 MIME-Type이 있습니까? text/javascript 등도 작동할 수 있지만, 그것에 대한 사양이 있습니까?

는 이미 언어 사양을 찾아봤지만 단서를 찾지 못했습니다.

TypeScript 파일을 제공하려는 이유를 알면 좋을 것입니다.

제가 알기로는, 타입스크립트는 자바스크립트로 컴파일하는데 사용되며, 자바스크립트는 브라우저에서 실행됩니다.현재 TypeScript에 대한 네이티브 지원이 없습니다(잘못되면 수정).

IIS를 통해 .ts 파일을 계속 제공하려는 경우에도 .ts와 연결된 IIS 관리자에서 사용자 정의 mime 유형을 추가할 수 있습니다.이 표준은 접두사를 정의합니다.x.,vnd.그리고.prs.및 vnd. 접두사는 표준화된 mime type text/application/에도 나열되어 있습니다.

그래서, 당신의 사용법에 따라, 당신은 있습니다.text/x.typescript또는text/prs.typescript.

이것을 web.config에 붙입니다;

<configuration>
    ...
    <system.webServer>
        <staticContent>
            <mimeMap fileExtension=".ts" mimeType="application/x-typescript" />
        </staticContent>
    </system.webServer>
</configuration>

데노우즈application/typescriptTypeScript 파일을 제공하여 다음을 사용하여 파일을 실행할 수 있습니다.

deno run "https://example.com/file.ts"

또한 의견을 제시해야 할 수도 있습니다.TypeScriptAssetHandler.ts 파일을 Javascript로 변환합니다.

 <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 유형을 텍스트/일반으로 설정하기만 하면 됩니다.이렇게 하면 보고된 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

언급URL : https://stackoverflow.com/questions/13213787/whats-the-mime-type-of-typescript

반응형