Typescript is not only a transpiler but also capable of generating source maps for easier debugging. The output of Typescript closely resembles the source code itself, allowing you to easily debug the resulting JavaScript files.
However, when dealing with a large bundled JavaScript file and needing to debug individual TypeScript files, exporting source maps becomes essential.
Typescript provides several sourceMapping flags that can be utilized. Refer to https://www.typescriptlang.org/docs/handbook/compiler-options.html for more information.
All modern web browsers are equipped to load source maps and map breakpoints back to their respective source files.
You have the option to bundle the source map and sources within your .js file, although this will significantly increase the file size.
tsc --sourceMap --inlineSources --inlineSourceMaps
Alternatively, if your web server is capable of serving the .ts and .map files, you can configure it using:
tsc --sourceMap --sourceRoot <root of src>
The latter approach will result in additional sourceMappingUrl comment at the end of the js files, requiring the browser's devtools to search for the .map and source files.