Compiling TypeScript files into multiple JavaScript files using Visual Studio 2015 Update 1

I am working on a project that involves multiple Typescript files and I am trying to find a way to compile specific groups of these files into separate JS files. For example:

  • Scripts\Group1\file1.ts
  • Scripts\Group1\file2.ts
  • Scripts\Group2\file3.ts
  • Scripts\Group2\file4.ts

The desired output after compilation (on save) would be:

  • Scripts\group1.js
  • Scripts\group2.js

I have explored the option of using multiple tsconfig.json files, however, I encountered difficulties getting my project to recognize even one tsconfig.json file. It appears that there are issues with tsconfig.json and VS2015.

Can the Visual Studios TypeScript compiler handle compiling to multiple JS files simultaneously?

My environment includes: VS2015 update 1, TypeScript 1.7.6.0 (included in VS update 1), .net 4.6 web application

Thank you!

Answer №1

Successfully implemented through npm and gulp. For those attempting a similar task:

package.json

{
  "version": "1.0.0",
  "name": "ASP.NET",
  "private": true,
  "devDependencies": {    
    "gulp": "3.9.0",
    "gulp-typescript": "2.10.0",
    "gulp-concat": "2.6.0",
    "gulp-sourcemaps": "1.6.0"    
  }
}

gulpfile.js (portion for generating 1 file)

var gulp = require('gulp');
var typescript = require('gulp-typescript');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('compileTypeScriptFiles', function () {
  var tsResult = gulp.src(['Scripts/file1.ts', 'Scripts/file2.ts'])
    .pipe(sourcemaps.init()) // Sourcemaps will be generated 
    .pipe(typescript({
      noImplicitAny: false,
      target: 'ES5',
      removeComments: true,
      out: 'final.js',
      preserveConstEnums: true,
      noEmitOnError: false
  }))
  .pipe(sourcemaps.write('.')) // Write sourcemap to same folder
  .pipe(gulp.dest('Scripts'));
});

For local development (VS 2015) link the action to Task Runner Explorer after build.

For TFS build server, follow these steps:

  • Install node.js (https://nodejs.org/en/blog/release/v0.12.0/)
  • Install rimraf. This is necessary to delete the node_module folder in your build since windows has deletion issues with this specific folder. Open the node cmd and execute "npm install rimraf -g"
  • Create a powershell script and attach it to the pre-build event.

My powershell snippet

Param (
  [string]$path = $env:TF_BUILD_SOURCESDIRECTORY
)

cd $path

# Install npm from package.json. An error might occur here due to outdated scripts but can be ignored.
&npm --loglevel=error install 

# Compile typescript using gulpfile.js
&node_modules\.bin\gulp compileTypeScriptFiles

# Remove node modules.
&rimraf $path\node_modules

Hopefully this information proves useful.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The issue arises in React when input elements fail to render correctly following a change in value, specifically when the keys remain identical

Click here to view the code sandbox showcasing the issue The code sandbox demonstrates two versions - a working one where Math.random() is used as the key, and a not working one where the index of the array is used as the key. When the array this.state.v ...

Can Angular components be used to replace a segment of a string?

Looking to integrate a tag system in Angular similar to Instagram or Twitter. Unsure of the correct approach for this task. Consider a string like: Hello #xyz how are you doing?. I aim to replace #xyz with <tag-component [input]="xyz">&l ...

New substitute for extending the extent in OpenLayers 4

I am currently in the process of migrating my code from OpenLayers 3 to OpenLayers 4 using TypeScript. Previously, I had a code snippet that extended the extent of my map so that all vector shapes I drew would be visible upon loading... angular.forEach(w ...

Exploring the Node environment setup within Nest.js

Currently, I am in the midst of setting up a Nest.js project and seeking an efficient solution for defining the Node environment used by the ConfigService to load environment variables: import { Module } from '@nestjs/common'; import { ConfigSer ...

Retrieve objects from an array that contain a certain specified key

I am trying to extract the objects from All_reports that contain the key: comentarioAdmin. Currently, I am retrieving all reports from All_reports, but I only want the reports that have the key comentarioAdmin. Thank you! getReports() { this.Service.g ...

Guide to sending jQuery data back to main class in TypeScript

Hi everyone, I'm diving into the world of typescript and JQuery. I have a simple question. In my typescript class called DatePicker, I am calling a function. Here's a snippet of the code: Class DatePicker { private pickerData; public update( ...

Switching from a TypeOrm custom repository to Injectable NestJs providers can be a smooth transition with the

After updating TypeORM to version 0.3.12 and @nestjs/typeorm to version 9.0.1, I followed the recommended approach outlined here. I adjusted all my custom repositories accordingly, but simply moving dependencies into the providers metadata of the createTe ...

Creating a HTML element that functions as a text input using a div

I am encountering an issue with using a div as text input where the cursor flashes at the beginning of the string on a second attempt to edit the field. However, during the initial attempt, it does allow me to type from left to right. Another problem I am ...

Preventing specific directories from being imported in a Typescript project

I am intrigued by the idea of restricting files within a specific scope from importing files from another scope. Let's consider this example: Imagine we have the following project structure: project/ ├── node_modules/ ├── test/ ├── ...

Utilizing Typescript with tfjs-node to effectively integrate the node-gpu version with regular node functionalities

I am facing challenges while running my Tensorflow.js node application with and without the GPU library. In vanilla JavaScript, examples show using require() for either @tensorflow/tfjs-node or @tensorflow/tfjs-node-gpu. However, in my TypeScript setup, I ...

When evaluating objects or arrays of objects to determine modifications

How can we detect changes in table data when users add input to cells? For example, if a user clicks on a cell and adds an input, the function should return TRUE to indicate that there are changes. If the user just clicks on the cell without making any ch ...

A guide on applying color from an API response to the border-color property in an Angular application

When I fetch categoryColor from the API Response, I set border-left: 3px solid {{element.categoryColor}} in inline style. Everything is functioning correctly with no development issues; however, in Visual Studio, the file name appears red as shown in the i ...

Having trouble with my Angular CLI post request to localhost:3000, could be due to an issue with my Proxy setup

I've set up a basic local API that focuses solely on handling post requests. I'm currently attempting to integrate this post request into my Angular application, but the results are rather puzzling. It seems like there's a misstep on my end, ...

Tips for toggling visibility in Angular 2

I utilized [hidden] in the following way where the value of "secondTab" is set to true. <form #siteForm="ngForm" novalidate (ngSubmit)="saveSite(siteForm.value,siteForm.valid)" class="admin-modal"> <div class="txt-danger">{{errorMessage}}&l ...

"When a class extends another class and utilizes properties within a static property, it essentially becomes

I have been encountering challenges with generics in TypeScript for quite some time now. My current setup is as follows: First, there is a generic class defined as: class Entity { public static schema = {}; } Then, there is a class that extends the ...

methods for determining the child type of an interface in TypeScript

I am currently working on implementing an event bus and have organized all event names and parameters in one interface. Here is how it looks: interface A { a: { x: number y: number } b: { name: string } } function on<T exte ...

When working with create-react-app and TypeScript, you may encounter an error stating: "JSX expressions in 'file_name.tsx' must

After setting up a React project with TypeScript using the CLI command create-react-app client --typescript, I encountered a compilation error when running npm start: ./src/App.js Line 26:13: 'React' must be in scope when using JSX react/r ...

There is an absence of the deployment template during deployment initialization

What steps can we take to guarantee the existence of a deployment template? I am in the process of deploying my logic app, and so far I have followed these steps: https://i.sstatic.net/UcCso.png https://i.sstatic.net/hPsap.png But where exactly is the ...

An error occurred while trying to add a property to an array because the object is not extensible: TypeError -

In my code, there is an object named curNode with the following structure: { "name": "CAMPAIGN", "attributes": {}, "children": [] } I am attempting to add a new node to the object like this: curNode!.children!.push({ name: newNodeName, ...

The Jest type definitions seem to be malfunctioning in this TypeScript project

Recently, I began a new Typescript project utilizing GTS. While the typings are functioning correctly for regular *.ts files, I am encountering difficulties in getting *.spec.ts files to work. Issue Each jest function is being flagged as red by ESLint wit ...