I am starting with typescript. I started with an empty folder and ran these commands to set up my typescript development.
JavaScript
x
4
1
npm init
2
npm install typescript
3
npm install @types/node
4
then i made a tsconfig file
JavaScript
1
2
1
npx tsc --init
2
I tried changing my output dir in tsconfig.json like "outDir": "./dist"
,
But that doesn’t seem to work. the transpiled file is still coming into the src folder. I have a folder structure like :
JavaScript
1
9
1
root
2
|_ node_modules
3
|_ src
4
|_ index.ts
5
|_ dist
6
|_package.json
7
|_tsconfig.json
8
|_package-lock.json
9
Here is the tsconfig.json file
JavaScript
1
12
12
1
"compilerOptions": {
2
"target": "es5",
3
"module": "commonjs",
4
"outDir": "./dist",
5
"rootDir": "./src",
6
"strict": true,
7
"esModuleInterop": true,
8
"skipLibCheck": true,
9
"forceConsistentCasingInFileNames": true
10
}
11
}
12
Advertisement
Answer
Just use tsc
. You just specify one file. TypeScript doesn’t worry about making it work as a module by itself as you don’t have a need for modules with just one file.
Oh also, from the cli reference:
Transpile just the index.ts with the compiler defaults
tsc index.ts