Luc Luc - 1 year ago 79
TypeScript Question

Best way to build single javascript file for all of my pages with Typescript

We are currently using RequireJS with CoffeeScript to generate custom JS files. However, we are not using the "r.js" compiler tool to optimize the code with the "define" header. Our current implementation requires that we put the full

statement at the top of each coffee file:

define('charts/bar', ['charts/base','constants'], (BaseModel, Constants) ->
class BarChart extends BaseModel

We are looking to move to TypeScript so we can make use of refactoring and all the other goodness that comes with it. The problem that we are running into is that we have not been able to figure out how to compile all of our TypeScript files into a single file.

For example, assume the following files:

  • charts/

    • bar.ts

    • line.ts

    • base.ts

  • users/

    • profile.ts

    • security.ts

    • friends.ts

  • data/

    • geo.ts

    • population.ts

    • voting.ts

With all of these files, we want to put them into a single file called
and reuse this js file across multiple pages. One page might only use the users/security class, while the next page might use the data/geo class along with some of the various chart classes.

How can we construct this using requirejs?

Note: One thing to keep in mind is that we don't have a single entry point to this class. It's purpose is solely to be used for helper classes and base implementations that we can extend in other classes.

Answer Source

How can we construct this using requirejs?

Use import/require and compile with option --module amd.


PS: highly recommend moving to commonjs. But that is opinionated

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download