3

I recently upgraded to 0.9.5 and instead of using build events to compile my typescript application, I decided to use the built in options in the project settings page. Specifically the tickbox that 'compile(s) javascript into one file'

In short I cannot get the files to compile in the correct order. The compilation is fine but when I run it, I can see that the files order is not correct so sub classes throw errors because their base classes are not defined.

Previously (in the build events method) I would specify the file I am compiling ('Main.ts'). Inside the target Main.ts file I used a number of reference tags to other files and that would compile everything into a single file all in the correct order.

Now in 0.9.5 I dont know how Im supposed to that. There is no option to specify which file is the one I want to compile. On their blog entry they mention using a _references.ts file. I cant find any documentation on this - so I presume this is correct:

I create a file called _references.ts which supposedly is passed to the compiler first. Inside that file I list all my reference commands like so:

/// <reference path="core/a.ts" />
/// <reference path="core/b.ts" />
/// <reference path="core/c.ts" />

But if I do this the compilation keeps randomising the build order. Its like its completely ignoring either the _references.ts file or the reference tags of that file. (I've tried putting them into another file but how do I tell it that that file must be passed first?)

Im probably wrong, but its my suspicion that its compiling all the files and it just so happens that the _references file comes in last.

So in short... How do I tell the compiler (in the new 0.9.5 settings panel) to compile everything into 1 file and also keep the order.

Thanks online

Mat
  • 961
  • 12
  • 28

2 Answers2

3

_references.ts can be used to control the order of your combined output.

Make sure you are using _references.ts somewhere in at least one of your .ts files, otherwise the compiler doesn't know about the existence.

To do so, add a reference to the _references.ts in one or more of your .ts files ;)

Now order the .ts references within that file as you want.

I tested it with the Raytracer example from the playground. I split all components into separated files and added the references... , my _references.ts looks like this:

/// <reference path="IThing.ts" />
/// <reference path="ISurface.ts" />
/// <reference path="IScene.ts" />
/// <reference path="IRay.ts" />
/// <reference path="IIntersection.ts" />
/// <reference path="ILight.ts" />
/// <reference path="Vector.ts" />
/// <reference path="Color.ts" />
/// <reference path="Camera.ts" />
/// <reference path="Sphere.ts" />
/// <reference path="Plane.ts" />
/// <reference path="Surfacse.ts" />
/// <reference path="RayTracer.ts" />
/// <reference path="Init.ts" />

I also used the option to generate one output file and it generates it in perfect order...

MichaC
  • 13,104
  • 2
  • 44
  • 56
  • 1
    Hi MichaC, I think I figured out what was wrong. I created the references file, however it was not in the root directory of the project. Not sure if this is an issue or not - but it only seems to work for me if I do that. Originally I had it in a sub folder. – Mat Dec 30 '13 at 13:45
  • no it must not be in the root. It is just important to notice that the `path` of each reference is a relative path to the location of the _reference.ts. Meaning if you have it in a sub directory, the path to the referenced files must reflect that, otherwise the compiler cannot find the files... And as I mentioned, you must reference the _reference.ts at least once in your other .ts files ;) – MichaC Dec 30 '13 at 14:07
2

I've found a pretty bad bug in the way VS compiles the _references.ts file during a full build (meaning Ctrl+F5 opposed to just Ctrl+S).

If you're having problems getting _references.ts to put your files in the corrcet order please see my question and answer here:

Visual Studio 2013 Typescript compiler isn't respecting '_references.ts' file

The simple fix is to edit the .csproj file (unload project first) and then move the _references.ts file to be first in the list of included ts files.

Community
  • 1
  • 1
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689