How to compile a specific file using tsc using the path compiler option

I have several files that I want to compile with a script. These files rely on a compilation option pathsto solve their modules. Since I want to specifically target these files, I must provide them tsc(since I do not want to create a separate tsconfig.jsonone that is designed for these files for this task)

I considered the option of passing a parameter --pathto tsc, but this is not allowed ( error TS6064: Option 'paths' can only be specified in 'tsconfig.json' file.)

Is it possible in some way to compile only those files .tsusing the parameter paths?

Update (22-06-17)

As requested, some specific examples:

The relevant settings in the file are tsconfig.jsonas follows:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "Components/*": [
        "./src/Components/*"
      ]
    }
  }
}

therefore, the relevant part is setting up paths where you can create shortcuts for importing files from a specific directory. so you can import a file of type import {header} from 'Components/header.ts'insteadimport {header} from '../../Components/header.ts'

But I need to compile specific files from the command line. But if I try:

tsc --project tsconfig.json entryFile.ts

he will give me an error:

error TS5042: Option 'project' cannot be mixed with source files on a command line.

and if I try to provide a parameter pathsfor cli, I get the following error:

error TS6064: Option 'paths' can only be specified in 'tsconfig.json' file.
+4
source share
2 answers

Setting input files on the command line disables your tsconfig.json.

When input files are specified on the command line, tsconfig.json files are ignored.

From TypeScript docs .

, , tsconfig.json include. , :

tsconfig.json , extends.

, , include tsconfig :

{
  "extends": "./tsconfig.json",
  "include": [
      "src/root/index.ts"
  ]
}

, script, :

  • 'extends tsconfig' 'include'
  • tsc --project, tsconfig

, , . , . watch (-w) , , , , .

+4

- .ts

. , .

tsc src/foo.ts
0

Source: https://habr.com/ru/post/1679815/


All Articles