bugmagnet
bugmagnet

Reputation: 7769

How to compile one typescript file in a larger project to a different file extension?

Here's my tsconfig.json

{
  "compileOnSave": true,
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "target": "ES3",
    "lib": ["ESNext"],
    "strict": false,
    "moduleResolution": "node",
    "module": "commonjs",
    "types": ["d.ts"],
    "removeComments": true
  },
  "include": ["*.ts"]
}

My project has a number of .ts files and a file of types in d.ts/index.d.ts.

I want to compile just one, JUST ONE, of the .ts files in my project and output it to a file with an .rr extension.

--outFile works but I can't figure out what the CLI is supposed to be told such that all the settings in the tsconfig.json apply. Currently I get a screenful of errors about TS2304: Cannot find name 'blah'

Upvotes: 1

Views: 81

Answers (1)

Shivam Pandey
Shivam Pandey

Reputation: 3936

outFile is working with below configurations. outFile can be used with amd or system module only. I tried your config where facing issues for lib. If I remove it, everything works as expected.

{
    "compilerOptions": {
        "target": "es5",
        "module": "system",
        "outFile": "./output/test.rr",
        "rootDir": "./",
        "strict": true,
        "esModuleInterop": true,
        "skipLibCheck": true
    },
    "include": [
        "./testfile.ts"
    ]
}

Your configuration after making changes, module and removing lib and types,

{
    "compileOnSave": true,
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "outFile": "./output/testfile11.rr",
        "target": "ES3",
        "strict": false,
        "moduleResolution": "node",
        "module": "system",
        "removeComments": true
    },
    "include": [
        "testfile.ts"
    ]
}

Upvotes: 1

Related Questions