2

I am creating an installer, in which a user will upload a zip folder containing ts files and my installer will compile it run-time and add it into wwwroot folder to be used in application.

There is no debug mode, as it is kind of adding plugin into website.

Please guide me here, what can I do to compile typescript files.

Amna
  • 603
  • 7
  • 30

2 Answers2

0

Just use tsc command line. You can add tsc through npm, or use it as ussualy command line through path variable

About your alghoritm:

  1. get your ts-string
  2. create file in server
  3. call tsc for this file
  4. return into client command like load X.js file from server
  5. into client append to body html like: $('body').append('<script src='X.js'></script>
  • 1
    Its not like this. The application is deployed on a server and I need to perform the compilation on any button click. I need to add my created plugin in a running application. – Amna Jun 01 '17 at 05:56
  • @Amna did you find a way? – ZenVentzi Aug 13 '21 at 17:09
0

This is what works for me.

tsc --p ./ --outDir ./build -d false --sourcemap false

This command does things list below:

  1. --p, compile typescript project with tsconfig.json in followed directory. (in this example it's ./)
  2. --outDir, compile all typescript file into .js file, to target directory. (in this example it's ./build)
  3. -d false, ignore .d.ts.
  4. --sourcemap false, compile without .js.map.

After that you can get a clean build with only .js.

Val
  • 21,938
  • 10
  • 68
  • 86
  • this is command lines command. what I am talking includes some backend c# code. There will be no cmd available to do this stuff. – Amna Jun 01 '17 at 08:02
  • 1
    @Diana but you cannot compile typescript file without `tsc`, the official typescript compiler. Maybe have a try to execute command with `System.Diagnostics.Process`? https://stackoverflow.com/a/1469790/681830 – Val Jun 01 '17 at 08:05