提问人:Anton Duzenko 提问时间:4/3/2019 更新时间:4/3/2019 访问量:541
Typescript:compilerOptions.outDir 和非 ts 模块
Typescript: compilerOptions.outDir and non-ts modules
问:
我在非 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>
...
当转译的 javascript 尝试将我的文本模块加载为 http://localhost:8082/text.dat 但原始文件位于 /src 文件夹中并且不会复制到 /public 时,这会导致 HTTP 404。
我错过了什么?
FWIW,完整的重现案例源位于 https://github.com/duzenko/typescript-non-ts-module-bundle
答:
1赞
Schroedinger
4/3/2019
#1
不幸的是,这在打字稿编译器中不受支持 Typescript Github 问题 这里
如果您使用的是 yarn 或 NPM,我建议您做的是有一个脚本,在成功编译后将这些文件移动到正确的位置。假设您在 src 中有一个文件。运行并输出到目录后,然后运行手动src/foo/bar.biz
tsc
./build
cp src/foo/bar.biz build/foo/bar.biz
评论