Knaģis
Knaģis

Reputation: 21485

Preserve license comment in TypeScript compiled output

TypeScript compiler provides an option to remove or retain comments in the compiled JavaScript output.

What I need is the ability to remove all comments but to keep one specific comment that is in the beginning of the file containing the license text.

I am using the compiler from node.js code so a solution that works from code (and is not exposed via tsc).

I cannot just prepend the license text to the resulting file since that would invalidate the source mapping.

Upvotes: 2

Views: 1293

Answers (1)

Dick van den Brink
Dick van den Brink

Reputation: 14557

In older versions of TypeScript you could do this with pinned comments like below:

/*!
 * Test
 */

These comments would still be present after compiling with --removeComments. This feature is gone/broken in TypeScript 1.4 but works again in the latest GitHub source code. So I think it will work again in TypeScript 1.5! :)

For future reference it was fixed in master a few days ago: https://github.com/Microsoft/TypeScript/pull/2406

Upvotes: 5

Related Questions