【问题标题】:How to compile typescript with babel 7 cli?如何使用 babel 7 cli 编译打字稿?
【发布时间】:2019-01-19 22:57:41
【问题描述】:

这个:

babel ./src/MyTypescript.ts  --out-dir ./wwwroot/js/

不起作用(没有错误,只是'0已编译')。

.babelrc 包含 Babel 7 使用 webpack babel loader 编译 typescript 所需的所有内容:预设“@babel/typescript”和插件“babel-plugin-transform-class-properties”(对我来说适用于当前的 babel 7 rc01).

【问题讨论】:

  • 为什么要在 typescript 中使用 babel?为什么不简单地使用 typescript 编译器?
  • 只是为了研究和调试(从bundle中提取转译的TS代码相当复杂)
  • 如果 somobody 可以向我解释 @babel/typescript 是错误(或好)的想法,我会非常高兴。现在这个困境“用什么 tsc 或预设” - 让我瘫痪。
  • @AkashKava:this post 详细说明了为什么您只想使用 Babel 7,而不使用 TypeScript(但使用 TypeScript 插件)。

标签: typescript babeljs babel-loader


【解决方案1】:

这是一个答案:

 babel ./src/MyTypescript.ts  --out-dir ./wwwroot/js/ --extensions '.ts,.js'

【讨论】:

    【解决方案2】:

    所选答案对我不起作用。

    我已经在以下链接的帮助下解决了:

    https://github.com/microsoft/TypeScript-Babel-Starter/blob/master/package.json

    "build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline"

    添加 TS 扩展:

    --extensions \".ts,.tsx\"

    【讨论】:

      猜你喜欢
      • 2019-07-01
      • 1970-01-01
      • 2017-06-10
      • 1970-01-01
      • 1970-01-01
      • 2013-08-19
      • 1970-01-01
      • 2021-06-26
      • 2015-12-17
      相关资源
      最近更新 更多