Search code examples
typescriptwebpackbabel-loaderts-loader

Do I need babel-loader on top of tsloader to transpile typescript with webpack?


I am writing webpack.config.js to transpile typescript (to be more precise tsx) into ES5 using tsloader and babel-loader. I have two questions:

1) Do we still need babel-loader even though tsloader output ES5 files?
2) Does it make sense to set compilerOptions.module in tsconfig.json to es6 when the target is es5?

tsconfig.json is as follows:

{
  "compilerOptions": {
    "module": "es6",
    "target": "es5",
    "jsx": "react"
  }
}

Thanks in advance.


Solution

  • 1) Do we still need babel-loader even though tsloader output ES5 files?

    No, we don't, unless there's a need to use non-compliant features that aren't supported by TypeScript (usually there's none).

    2) Does it make sense to set compilerOptions.module in tsconfig.json to es6 when the target is es5?

    Yes. It outputs ES5 code with ES modules that can be processed by bundling system (Webpack or Rollup).