Typescript:compilerOptions.outDir 和非 ts 模块

Ant*_*nko 5 module typescript

我对非 ts 模块(文本资产)有一个问题,它们没有按照 tsconfig.json 中的配置转移到 outDir (或者我做得不对)。

这是最简单的重现案例

// /src/main.ts
import text from 'text.dat'
console.log( text )

// /src/a.d.ts
declare module 'text.dat' {
    const value: string;
    export default value
}

// /tsconfig.json
{
  "compilerOptions": {
    "target": "es5",                      
    "module": "system",                   
...
    "outFile": "./public/bundle.js",      
    "outDir": "./public",                  
...

// /public/a.html
...
    <script type="text/javascript" src="bundle.js"></script>
    <script>
        SystemJS.import('main');
    </script>
...
Run Code Online (Sandbox Code Playgroud)

当转译的 javascript 尝试将我的文本模块加载为http://localhost:8082/text.dat但原始文件位于 /src 文件夹中并且不会复制到 /public 时,这会导致 HTTP 404。

我缺少什么?

FWIW 完整的重现案例源位于https://github.com/duzenko/typescript-non-ts-module-bundle

Sch*_*ger 1

遗憾的是,打字稿编译器内部不支持此功能Typescript Github Issue here

如果您使用的是yarn 或NPM,我建议您使用一个脚本,在成功编译后将这些文件移动到正确的位置。假设您在 src 中有一个文件src/foo/bar.biz。运行tsc并输出到./build目录后,然后运行手动cp src/foo/bar.biz build/foo/bar.biz