gpt4 book ai didi

typescript :compilerOptions.outDir 和非 ts 模块

转载 作者:行者123 更新时间:2023-12-03 19:43:38 24 4
gpt4 key购买 nike

我对非 ts 模块(文本 Assets )有一个问题,它们没有按照 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 时,这会导致 HTTP 404但原始文件位于/src 文件夹中,不会复制到/public。

我错过了什么?

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

最佳答案

不幸的是, typescript 编译器不支持这 Typescript Github Issue here

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

关于 typescript :compilerOptions.outDir 和非 ts 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55489557/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com