In my endeavor to develop a javascript module using TypeScript that is compatible with ES5 browsers and NodeJs modules, I have encountered a dilemma. I wish to avoid using import and export in TypeScrtipt as it creates dependencies on SystemJS, RequireJS, or commonJs for the output. Instead, I opted to create a library with a namespace and implemented the following code to ensure compatibility with SystemJs:
// global html object (pure javascript compatiblity)
if (typeof window !="undefined") (<any>window).myNamespace = myNamespace;
// create exports
declare var module:any;
if (typeof module !="undefined") module.exports = {myNamespace};
Although this setup works fine, I now need to include additional code to utilize the library within NodeJS modules while maintaining proper typing information.
export {myNamespace}
This enables me to incorporate my library into NodeJs lib using the following syntax:
import {myNamespace} from "../lib/myNamespace.js";
However, I am struggling to find a way to instruct the TypeScript compiler to automatically append that export without creating its own module structure. Is there a method to seamlessly add custom lines at the end of the generated d.ts file after each compilation, similar to the following:
Generated typing ..
...
...
// Custom declaration
// Remark Remark
export {myNamespace}
// Remark Remark
**Note: ** The modulation is none and many aspects are customized, therefore the traditional export feature of typescript modulation cannot be employed.