Reputation: 961
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
Upvotes: 3
Views: 888
Reputation: 146000
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.
Upvotes: 2
Reputation: 13390
_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...
Upvotes: 3