I am currently developing multiple NPM packages using TypeScript and I am exploring the most effective strategies for supporting various target architectures.
When compiling to ES3, there is extensive support but it comes with additional boilerplate for compatibility reasons (resulting in larger file sizes and code that may be challenging to parse). On the other hand, targeting esnext results in clean output code without boilerplate, but with limited support.
An issue arises as the TypeScript compiler does not transpile JavaScript code or any code located within the node_modules
directory. This presents a challenge when compiling a library to ES6 and then trying to use it in a browser application that targets ES3 or ES5.
What approach should be considered best practice in this scenario? How should I configure my package.json
and tsconfig.json
? Additionally, if users of the library need to take action, what is the recommended method?
Thank you for your help!