【问题标题】:Typescript development environment打字稿开发环境
【发布时间】:2021-02-10 05:24:24
【问题描述】:

我从打字稿开始。我从一个空文件夹开始,然后运行这些命令来设置我的打字稿开发。

  npm init 
  npm install typescript
  npm install @types/node  

然后我制作了一个 tsconfig 文件

npx tsc --init

我尝试在 tsconfig.json 中更改我的输出目录,例如 "outDir": "./dist",

但这似乎不起作用。转译的文件仍然进入 src 文件夹。 我有一个像这样的文件夹结构:

                   root
                   |_ node_modules
                   |_ src
                     |_ index.ts
                   |_ dist
                   |_package.json
                   |_tsconfig.json
                   |_package-lock.json

这里是 tsconfig.json 文件

"compilerOptions": {
               "target": "es5",                          
               "module": "commonjs",
               "outDir": "./dist",                        
               "rootDir": "./src",    
               "strict": true,
               "esModuleInterop": true, 
               "skipLibCheck": true,                         
               "forceConsistentCasingInFileNames": true
  }
}

【问题讨论】:

标签: javascript node.js typescript tsconfig


【解决方案1】:

只需使用tsc。您只需指定一个文件。 TypeScript 并不担心让它本身作为一个模块工作,因为您不需要只有一个文件的模块。 哦,还有,来自 cli 参考:

仅使用编译器默认值 tsc index.ts 转译 index.ts

【讨论】:

    【解决方案2】:

    转译后的文件仍在 src 文件夹中。

    您还需要设置一个rootDir。在您的情况下,它应该是"rootDir": "src"。

    【讨论】:

    • 我试过没有帮助。似乎不知何故它没有拾取 tsoncfig 文件。
    • 默认是tsconfig所在的文件夹。
    猜你喜欢
    • 2020-11-22
    • 2019-12-13
    • 2018-02-23
    • 2016-02-20
    • 1970-01-01
    • 2020-08-15
    • 2021-12-05
    • 2022-09-27
    • 1970-01-01
    相关资源
    最近更新 更多