TypeScript compile all ts files as a single JavaScript file in WebStorm 7

I have a lot of .ts files in my project. WebStorm build each .ts file as a js file. But I dont want that.

I have an app.ts file and all other .ts files will be build in that app.ts file. How can I do that in WebStorm 7?

There is a solution in CLI mode but how can i implement it in WebStorm?

 tsc --out app.js main.ts app.ts a.ts b.ts

Or is there a better way to do this?

ANSWER

Just added this line at Arguments section in Edit Watcher

--sourcemap $FileName$ --out your-main.js

Answers:

Answer

You can specify --out option in Typescript File watcher arguments, and, if 'track only root files' option is on, all ts files will be merged into a main js file (that imports them all directly or via references chain) on modifying any of them

Answer

You could use grunt-ts which can maintain a reference.ts file for you, and point the webstorm file watcher to run your grunt task https://github.com/basarat/grunt-ts#javascript-generation-and-ordering

Disclaimer : I am one of the authors of grunt-ts.

Answer

For those who don't have a single file that links to all other ones and they don't want to maintain manually "references.ts" or using basarat's grunt-ts, here's my setup:

The basic idea is to list all your *.ts files into a text file and then use the file as a patameter for the tsc compiler. So I created my own file watcher and disabled the default one for TypeScript files. My file watcher's program is a bat file with following content:

dir /s /b /o:gn scripts\*.ts > ts_sources.txt
tsc %*

If you're on Mac or Linux you can easily transform this into a bash script.

On the watcher's setup screen you point to your batch file (bash script):

$ProjectFileDir$\compile.bat

and as your arguments you can have to use following:

@$ProjectFileDir$\ts_sources.txt --out $ProjectFileDir$\app_all.js --sourcemap

I guess there are many ways to do it...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.