4

I have 2 typescript files that share the same external module:

A.ts:

export module mymodule {
    export class MyClass {
    }
}

B.ts:

import a = require("A");
export module mymodule {
    export class MyOtherClass {
        new a.mymodule.MyClass()
    }
}

This all works nice and tidy in development and I enjoy type safety, dev support, debugging, etc. but for production, I would rather want to have it all in one JavaScript file.

Is that possible at all? I tried with --out and r.js but the combined files invariably end in nested define statements that make access to any class impossible.

If you are curious what we are trying to build: https://github.com/canoo/open-dolphin/tree/master/subprojects/client-javascript/js/dolphin

6
  • 1
    Highly recommend reading this typescript.codeplex.com/… Commented Dec 17, 2013 at 23:34
  • Hm, yes. That page actually inspired me to do the whole thing. When they say "One effect of this is that it's not possible to use the --out compiler switch to concatenate multiple external module source files into a single JavaScript file." Does that mean that there is no way? Commented Dec 17, 2013 at 23:40
  • You could hack something together that tried to merge the .js files, but from TypeScript itself there is no way. Are you wanting MyClass and MyOtherClass to merge into the same parent object? Commented Dec 17, 2013 at 23:45
  • Yes. All my classes live in the same external module and there is only one (but spread over many files). My goal was to avoid naming conflicts. Commented Dec 18, 2013 at 0:00
  • The only way all your classes live in the same external module is if you only have one .ts file. See the "Needless namespacing" section of the linked page. Commented Dec 18, 2013 at 0:08

1 Answer 1

1

Based on the comments above, I could create a bundle for my special case.

Please see the "requireJs" task in https://github.com/canoo/open-dolphin/blob/master/subprojects/client-javascript/dolphin-client-javascript.gradle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.