Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

How can typescript generate single one javascript file without reference typescript file code

Can typescript generate single one javascript file without reference typescript file code?

Here are two typescript source files.

Class source1{...};

Class source 2{...};

Here are another two typescript files.

///reference path=’source1’

Class reference1{...};

///reference path=’source2’

Class reference2{...};

I will generate reference1 and reference2 to single one js file. But in the js file, there are source1 and source2 code. How can I get single javascript file without souce1 and soucre2 code?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Looks to me that you need to split your compilation into two phases, one to generate soruce1 and soruce2, and another one to generate reference1 and reference2. The best way to do this is to generate a .d.ts from the first batch of files then reference that in your second compilation.

to generate sources.d.ts:

tsc --declaration --out soruces.js soruce1.ts source2.ts 

now your files should look like:

///reference path=’sources.d.ts’

Class reference1{...};

///reference path=’source.s.ts’

Class reference2{...};

the second compilation would be:

tsc --out references.js reference1.ts reference2.ts 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...