Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I'm creating an Angular2 app using typescript, and every time I run npm start, all of my .ts files are compiled into javascript files and put in the directory. Is there anyway to turn this off.

package.json

 {
  "name": "angular-prac",
  "version": "1.0.0",
  "scripts": {
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" ",    
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "typings": "typings",
    "postinstall": "typings install" 
  },
  "license": "ISC",
  "dependencies": {
    "angular2": "2.0.0-beta.7",
    "systemjs": "0.19.22",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.2",
    "zone.js": "0.5.15"
  },
  "devDependencies": {
    "concurrently": "^2.0.0",
    "lite-server": "^2.1.0",
    "typescript": "^1.7.5",
    "typings":"^0.6.8"
  }
}
share|improve this question
    
Can you post your npm config? It's hard to know what the problem is if we don't know what npm start actually runs. – Joe Clay Feb 26 at 22:21
    
I added package.json, is that what you are looking for – xeroshogun Feb 26 at 22:37
    
Sorry for the slow response. I think I know what the issue is - posted an answer below. – Joe Clay Feb 26 at 23:38

The issue is most likely with your tsconfig.json - this is the file (usually located in your project root, alongside package.json) that contains the configuration for your TypeScript build. By default, it just compiles the files in place, leading to the situation you're describing where your source folder fills up with compiled Javascript files. The options you'll need to add will depend on what you want the end result to be:

If you want all the resulting files to be concatenated into a single output file:

{
    "compilerOptions": {
        "outFile": "./dist/app.js"
    }
}

If you want all the resulting files to be output into a separate folder (but still as individual files):

{
    "compilerOptions": {
        "outDir": "./dist"
    }
}

Of course, if there's already a tsconfig.json there, you'll want to add these options, rather than replacing the entire thing.

There are a massive amount of options available for configuring the TypeScript build process - if you want to tweak it some more, you can find info on the wiki, or if you need some more examples, let me know and I'll edit them into the answer.

share|improve this answer

In fact, when running the "npm run start" command, both TypeScript compiler and lite-server are started. If you only want to run the HTTP server, you could run the following command:

$ npm run lite

This way TypeScript files won't be compiled again at startup and you will use the previously compiled JS files to execute your Angular2 application.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.