nanomosfet
nanomosfet

Reputation: 132

How to move all the compilation files out of the src directory

It is quite annoying seeing the .js, .map, .spec, etc. in the src file of my angular application. I want to just have my .ts files in that directory. Is there anyway to make it so the compiler will just put them into another directory and serve the app from there? Right now I am just developing locally.

Upvotes: 2

Views: 1606

Answers (2)

Aniruddha Das
Aniruddha Das

Reputation: 21688

you can do this by using typescript configuration file. Add outDir and your path where all the compiled file will be stored.

You can also mention to put all the compiled into one file by outFile

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

Upvotes: 2

DeborahK
DeborahK

Reputation: 60528

There are several ways to deal with this.

If you are using a code editor such as VS Code, one option is to "hide" the files in the editor. I use this in the settings.json file in VS Code:

// Place your settings in this file to overwrite default and user settings.
{
    "files.exclude": {
        "**/.git": true,
        "**/.DS_Store": true,
        "**/app/**/*.js": true,
        "**/*.map": true
    },
    // Controls auto save of dirty files. Accepted values:  "off", "afterDelay", "onFocusChange". If set to "afterDelay" you can configure the delay in "files.autoSaveDelay".
    "files.autoSave": "afterDelay"
}

Another option is to use the Angular CLI. It generates all of your .js and .map files in a dist folder by default so you don't have them in your src folder.

There are other suggestions here: Separate Angular2 TypeScript files and JavaScript files into different folders, maybe 'dist‘

Upvotes: 3

Related Questions