typescript 为什么要使用 babel-loader 和 ts-loader?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49624202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:19:52  来源:igfitidea点击:

Why use babel-loader with ts-loader?

typescriptbabel-loaderts-loader

提问by Yuriy

There is a TypeScript, Babel, React, and Karma Sample.

TypeScript、Babel、React 和 Karma Sample

The Webpack config contains babel-loader with ts-loader for .tsx?files.

Webpack 配置包含 babel-loader 和 ts-loader.tsx?文件。

Please explain why it is needed? Why isn't ts-loader enough?

请解释为什么需要它?为什么 ts-loader 不够用?

回答by Fateme Fazli

ts-loader: convert typescript (es6)to javascript (es6)

ts-loader:转换typescript (es6)javascript (es6)

babel-loader: converts javascript (es6)to javascript (es5)and Typescriptdoesn't do polyfills, which babeldoes. If you write client-side code in es6and want it to run on modern browsers, you'd probably need babel's polyfills.

babel-loader: 转换javascript (es6)javascript (es5)并且Typescript不做polyfillsbabel确实如此。如果你写的客户端代码es6,并希望它在现代浏览器上运行,你可能需要babelpolyfills

It is less justified with server-side code - just use the latest nodeversion for es6support. But babel still provides some goodies that tscdoesn't - like caching, or a huge range of plugins that can be very useful.

服务器端代码不太合理 - 只需使用最新node版本即可获得es6支持。但是 babel 仍然提供了一些tsc没有的好东西——比如缓存,或者大量非常有用的插件。

It's not necessary but a practice for using them all together.

这不是必需的,而是将它们一起使用的练习。