4

When I add a *.ts file to Visual Studio 2015 and this get compiled, the *.js file isn't a code behind file of the *.ts. It just resides in the folder and it's not part of the visual studio project.

Is that by design or did I break something in my project?

If it is by design, what is the motivation behind? (If i want to have a look at the file i have to show hidden files and eventually hit the refresh button... )

3 Answers 3

5

This is by design - the JavaScript file is a build artefact, just like a DLL.

The idea is that you check in your TypeScript code and allow the build server to create your JavaScript files. While you may be running in "Debug" mode, the build server can generate them in "Release" mode, which may have more optimisations enabled.

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

2 Comments

I would highly recommend this approach to people getting started with TypeScript. I don't commit js files to source control, and just run a task during the release build, and of course set to "Copy To Output Directory" option to "Do Not Copy" on each of my TS files so they don't get deployed.
ok thanks for the info. I don't know it just feelsfeels unnaturally strange to me not having them in the project. (You could say the same about less/css however they are included in the project..)
3

I don't know if this is deliberate or not.

If you want to include the JavaScript files in your project, you need to edit the project file manually. Open it up in Notepad (or your favourite text editor) and do the following;

  1. Look for

<Content Include="Scripts\yourfile.ts" />

  1. Change to

<Content Include="Scripts\yourfile.js"> <DependentUpon>yourfile.ts</DependentUpon> </Content>

The JavaScript file should now get pulled in.

You'll want this is you are using Visual Studio to publish your project to deployment.

Comments

0

If you want to change the output folder of the .js file(s) consider adding a tsconf.json file to your source folder. That way you can configure where the outputed .js file(s) ends up.

Eg:

{ "compilerOptions": { "target": "es5", "out": "www/scripts/appBundle.js", "sourceMap": true, "removeComments": true, "sourceRoot": "/" } }

The documentation for tsconfig.json can be found on github at this page.

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.