Tips for creating an output directory when the TypeScript files are stored in the './src' location

Here is what I currently have:

./src/myfile.ts
./test/mytest.spec.ts

I want tsc to output a javascript file (myfile.js) and a definition file (myfile.d.ts) in the ./build directory.

This is my tsconfig.ts:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "noImplicitAny": false,
    "rootDir": ".",
    "outDir": "./build",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "declaration": true
  },
  "files": [
    "./src/index.ts"
  ],
  "exclude": [
    ".vscode",
    ".git",
    "build",
    "node_modules",
    "test"
  ],
  "compileOnSave": false,
  "buildOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

The issue is that this configuration generates the myfile.js in the sub-folder ./build/src/.

Please note that setting "rootDir": "./src" causes the test folder not to be compiled, resulting in problems when running tests with karma + webpack.

Answer №1

After running tsc, two files should be generated: a JavaScript file named myfile.js and a definition file named myfile.d.ts in the ./build directory.

TypeScript is not optimized for handling bundling tasks. It is recommended to use another tool for bundling purposes.

For more information

For example, you can refer to this Webpack quickstart guide: https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html

Avoid using out or outFile options: https://basarat.gitbooks.io/typescript/content/docs/tips/outFile.html

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

Retrieve the latest entry from a JSON file containing epoch timestamps

Currently, I am in the process of developing an app using angularjs. In my json data, I have timestamps and corresponding values like below: { "dps": { "1455719820": 0, "1455720150": 0, "1455720480": 0, "1455720810": 0, " ...

Having trouble with popovers after upgrading to bootstrap v4

I am facing an issue while trying to migrate Bootstrap from version 3 to 4. The problem specifically lies with popovers and the popper.js library. Each time I hover over an element, the following error is displayed: Uncaught TypeError: Cannot read property ...

Can we convert a PHP frontend into a Vue node?

I'm currently working on transitioning a legacy PHP application to Vue, and I want to do it gradually. The current PHP app is quite messy, with HTML and JavaScript files intertwined in a complicated manner like this: foo.js.php ... <script src=&quo ...

Is there a way to update specific content within a view in express.js without having to re-render the entire view?

I'm in the process of creating a calendar that allows users to click on dates, triggering a popup window displaying events for that specific date. The challenge lies in not knowing which date the user will click on prior to rendering, making it diffic ...

What is the most effective way to compare a property with the values stored in an array of objects?

d : {"children":[{"name":"China","children":[{"name":"China","value":400,"percentage":"33.33"}],"index":0},{"name":"England","children":[{"name":"England","value":300,"percentage":"33.33"}],"index":1},{"name":"Malaysia","children":[{"name":"Malaysia","val ...

The custom validation in Node.js using Express-Validator is ineffective

I have implemented custom validators using express-validator to include specific validations: middlewares.js module.exports = function (app) { console.log('making sure I am being called'); return function (request, response, next) { ...

What is the correct way to outline the parameters for deactivating functions?

Request for Assistance! I am facing a challenge with multiple blocks in my WordPress website. Each block contains a checkbox, two select options, and an element that needs to be toggled based on the selected options in the dropdowns. The functionality to ...

There was an error trying to read properties of undefined, specifically the 'prototype', in a code using Next.Js and Express

While attempting to incorporate express into my next.js project, I encountered errors when trying to initialize express: const express = require('express'); The errors that appeared were: Module not found: Can't resolve 'async_hooks ...

Unit testing an Angular service using Jasmine with a JSON object schema in Angular 2/4

Looking for assistance with unit testing a service I have. The service includes a current json array object that is functioning properly when the observable is subscribed to. However, I seem to be encountering issues with my unit test setup. Can anyone pr ...

Using the Node.js mongodb-native library to insert multiple strings as separate documents

node: 8.9.4 mongo: 3.6.3 mongodb-native: 2.2.33 Query: How can I seamlessly insert an array of simple strings as new documents with just one call? I prefer not to pre-process the array before insertion. I'm in search of a magical mongo solution h ...

What is the best way to prevent useEffect from triggering when a modal is being rendered?

I'm currently developing a react movie application. I am facing an issue with the hero picture feature that displays a random popular movie or show. Whenever I click the button to open a modal, the useEffect function is triggered and changes the movie ...

Tips for building an interactive jQuery data table using JSON information and AJAX requests

Currently, I am attempting to develop a dynamic data table using jQuery and JSON. My objective is to extract the keys from the JSON data and utilize them as headers in the table, while the values within those keys will be displayed as rows. Here's th ...

Can someone please explain how I can extract and display information from a database in separate text boxes using Angular?

Working with two textboxes named AuthorizeRep1Fname and AuthorizeRep1Lname, I am combining them in typescript before storing them as AuthorizeRep1Name in the database. Refer to the image below for the result. This process is used to register and merge the ...

Transformation of Array of Objects to Array of Values using Node.js

I am looking to transform the following: [{ prop1: '100', prop2: false, prop3: null, prop4: 'abc' }, { prop1: '102', prop2: false, prop3: null, prop4: 'def' } ] into this format: [[100,false,null,'abc&ap ...

Overriding the w-4xl with sm:text-2xl in Tailwind CSS

Struggling to achieve responsive design on my Pages, especially with changing text size when the screen is small. I've been following all the correct steps and maintaining the right order. However, whenever I set 'sm', it seems to override a ...

Using AngularJS to pass objects dynamically through ng-include

Below is an example that is fully functional, except for one issue. When using node.title within the HTML code, everything works as expected. However, when trying to use {{node.title}} within the ng-include file, it does not function properly. Only the g ...

Show Particular Outcome at the Beginning of Array in ReactJS

I am working with an array of data that contains a list of names, and I need to sort it so that a specific name ("Fav Team") always appears at the top of the list. The array has two fields, homeTeamName and awayTeamName, that may contain this value. How ...

Tips for obtaining the top 3 highest-value objects in a JavaScript array over all other elements

I am working with an array that contains objects, each with two properties: name and value. array = [ { name: 'name1', value: 0 }, { name: 'name2', value: 2 }, { name: 'name3', value: 4 }, { name: 'n ...

swap out a JavaScript function for a fresh function

In our ordering system, there is a hidden function that I cannot access. Interestingly, this function contains a spelling error which causes a grammar issue to appear in a popup when a user interacts with it. Is there any way for me to either modify the t ...

The error at core.js:4002 is a NullInjectorError with a StaticInjectorError in AppModule when trying to inject FilterService into Table

While exploring PrimeNg Table control in my application - as a beginner in PrimeNg & Angular, I encountered an error No provider for FilterService! shown below: core.js:4002 ERROR Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(AppMo ...