11

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
1
  • 3
    Why did you copy the answer into your question? That's not how this website works. Commented May 12, 2018 at 13:55

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

3 Comments

'track only root files' is checked but which file is the main js file? Can I choose main file in settings? Can you explain me with more specific information, Thanks.
the target file name (the one I called 'main js') is the one you use with --out option (app.js in your example). When you modify any of your ts files, the compiler will follow the references (///<reference path=’AnotherFile.ts’/>) chain and concatenate all the referenced files into a single JavaScript file with the specified name (app.js)
Thanks this is work for me. I'll edit my question with answer.
1

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.

Comments

1

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...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.