So I was trying to compare the output compiled code by these 2 combinations.
ts-loader
{
test: /\.tsx?$/,
use: 'ts-loader',
}
babel-loader
use: {
loader: 'babel-loader',
options: {
presets:
[
"@babel/preset-react",
"@babel/preset-typescript",
]
}
}
Questions
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.
Babel excels at custom transformationsIf you need custom transformations, you'll need to use Babel. The good news is that most TypeScript tools allow you to both use TypeScript and then run the code through Babel afterwards, to get the best of both worlds.
Babel can be classified as a tool in the "JavaScript Compilers" category, while Webpack is grouped under "JS Build Tools / JS Task Runners".
If Babel is a translator for JS, you can think of Webpack as a mega-multi-translator that works with all kinds of languages (or assets). For example, Webpack often runs Babel as one of its jobs. Another example, Webpack can collect all your inline CSS styles in your Javascript files and bundle them into one.
for your questions:
Also you can mix the 2, have ts-loader for dev and babel for prod builds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With