Hedam
Hedam

Reputation: 2249

Optimize compiling of large TypeScript file

I have an autogenerated TypeScript file, that only exports an array of 65,000 small objects. The auto-generation is done on an ad-hoc basis, but the compilation is done each time the project is built. Since most of the build-time is spent on compiling this particular file, I would like to optimise it a bid.

This optimisation is primarily a good idea since the file is only being changed 1-3 times a year. Some other parts depend on this file, so I do not think I am able not to compile it.

Is it possible to somehow not compile a file, if it has not been changed, while still being able to reference it?

Upvotes: 0

Views: 1444

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 249706

You can use the --watch compiler option to incrementally build the project as files change. While this will save time on subsequent build, the first one will still be slow.

A better option might be to compile the file individually (when you generate), and generate a d.ts(using the "declaration": true option), which will probably be smaller and use the js file in your actual project instead. You could also keep the ts file in the project and use "exclude": ["file.ts"] in your tsconfig.json to nto build the fiel every time.

Upvotes: 1

Related Questions