Stef Stef - 2 months ago 19
TypeScript Question

How to build to output folder when the typescript files are located in './src'

What I have:

./src/myfile.ts
./test/mytest.spec.ts


And tsc should create a javascript (
myfile.js
) and definition file (
myfile.d.ts
) in the
./build
location.

My tsconfig.ts:

{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"rootDir": ".",
"outDir": "./build",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"declaration": true
},
"files": [
"./src/index.ts"
],
"exclude": [
".vscode",
".git",
"build",
"node_modules",
"test"
],
"compileOnSave": false,
"buildOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}


But this config file generates the
myfile.js
in the
./build/src/
sub-folder.

Note that I cannot use
"rootDir": "./src"
because then the test folder is not compiled (which gives problems when running tests with karma + webpack?)

Answer

And tsc should create a javascript (myfile.js) and definition file (myfile.d.ts) in the ./build location.

TypeScript is not nicely modeled to handle bundling. That is something you should use some other tool to do

More

e.g. Webpack quickstart: https://basarat.gitbooks.io/typescript/content/docs/quick/browser.html

Don't recommend out / outFile : https://basarat.gitbooks.io/typescript/content/docs/tips/outFile.html