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
Why use babel-loader with ts-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 Typescript
doesn't do polyfills
, which babel
does. If you write client-side code in es6
and want it to run on modern browsers, you'd probably need babel
's polyfills
.
babel-loader: 转换javascript (es6)
为javascript (es5)
并且Typescript
不做polyfills
,babel
确实如此。如果你写的客户端代码es6
,并希望它在现代浏览器上运行,你可能需要babel
的polyfills
。
It is less justified with server-side code - just use the latest node
version for es6
support. But babel still provides some goodies that tsc
doesn'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.
这不是必需的,而是将它们一起使用的练习。