Question

I am trying to use typescript with modules as namespaces with the folder structure

/ns1/ns2/class1.ts
          class2.ts
usage.ts

where usage.ts can do:

new ns1.ns2.class1();
new ns1.ns2.class2();

If this were pure js I would do it all with requirejs.

  1. Create modules without namespace
  2. Reference the modules for usage
  3. Use R.js to compact the require objects into one file

I have found that

  • Setting AMD mode on typescript generates modules, but doesn't play well with their export as each module has to be imported via import statement as the ns is no longer global

My question:

What is the proper way to compact the lets say 300 generated js files since you wouldn't with r.js?

And

Has anyone found a better way with typescript to:

  • do a require('ns1',function(ns1){...}) such that i can do new ns1.ns2.class1(),new ns1.ns2.class2()
  • keep all classes in their own files and in those namespaces

It seems like you can either have modules or everything global in namespaces... not both.

Was it helpful?

Solution

If you have two typescript files referencing each other using ///reference and you compile with --out compiler flag, typescript will merge the two (or n number of) files for you

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top