My Vision
I am aiming to develop a versatile library that can cater to both JavaScript and TypeScript developers for frontend applications, excluding Node.js. This means allowing JavaScript developers to utilize the library as inline script using
<script type="text/javascript" src="mylib.js">var myLib = new MyLib();</script>
, while enabling TypeScript developers to import the library's modules.
My Requirements
To achieve this goal, I require a build solution with the following capabilities:
- The library must be developed in TypeScript.
- The build process should automatically include all necessary declarations, facilitating module imports by TypeScript developers.
- For JavaScript users, traditional usage via inline code within a
<script>
Tag should be supported. - Automatic generation of builds upon executing
npm run build
. - The library should strive for maximum compatibility with older browser versions.
Challenges Faced
- I have experimented with different settings in the tsconfig.json file for my TypeScript library. One approach involved setting the "module" attribute to "none", but this resulted in limitations such as inability to use imports/exports and the need to merge TypeScript files into one, complicating development.
- I've examined repositories like Konva.js, which achieves similar goals. However, grasping the methodology behind it remains a challenge. It appears the developer converts the code to UMD format, utilizes Rollup.js, and ultimately produces a JavaScript file along with the required TypeScript code at the end of the build process.
Seeking Assistance
Despite exploring various avenues for days, pinpointing the exact solution has proven elusive. Hence, seeking guidance here in hopes of finding a suitable resolution. Any help would be greatly appreciated.