Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use babel-loader with ts-loader?

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

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

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

like image 614
Yuriy Avatar asked Apr 03 '18 07:04

Yuriy


People also ask

Why do I need Babel with TypeScript?

By using babel's support for TypeScript, you get the ability to work with existing build pipelines and are more likely to have a faster JS emit time because Babel does not type check your code.

Does babel-loader work with TypeScript?

As a work-around, we can use babel-loader to compile TypeScript.

Why do I need babel-loader?

babel-loader exposes a loader-builder utility that allows users to add custom handling of Babel's configuration for each file that it processes.


1 Answers

ts-loader: convert typescript (es6) to 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.

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.

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

like image 114
Fateme Fazli Avatar answered Oct 04 '22 02:10

Fateme Fazli