How can I pass multiple source files to the TypeScript compiler?

后端 未结 6 1260
忘掉有多难
忘掉有多难 2020-12-14 05:54

TypeScript is designed for large-scale JavaScripty projects which typically consist of multiple internally produced files along with externally produced libraries. How does

相关标签:
6条回答
  • 2020-12-14 06:28

    With TypeScript 1.5 (beta but the final version should be there soon), you can create a tsconfig.json file to configure the TypeScript compiler and the files to compile (among other things). See my answer over there: How to watch and compile all TypeScript sources?

    0 讨论(0)
  • 2020-12-14 06:29
    dir *.ts /b /s > ts-files.txt
    tsc @ts-files.txt
    del ts-files.txt
    

    This will compile all *.ts files in working directory and its sub directories. If you don't want to include sub directories, just remove the /s part from the first line.

    Note that you can also add other arguments to the tsc line. Here is what I'm using now for one of my projects:

    tsc @ts-files.txt --out ..\output\deerchao.web.js --removeComments
    
    0 讨论(0)
  • 2020-12-14 06:30

    tsc can compile multiple sources in sequence if you just give the names in order:

    tsc foo.ts bar.ts
    

    You can also pass a text file containing a list of files and command line arguments from a text file using the @ command line argument.

    tsc @compile.txt
    

    and the compile.txt could look like this:

    --module amd
    foo.ts
    bar.ts
    

    Also note that if on file references another via an import, tsc will automatically figure that out without you having to explicitly list the file that it depends on.

    0 讨论(0)
  • 2020-12-14 06:32

    Or simply:

    find ./my/path/ -name \"*.ts\" -type f | tsc
    
    0 讨论(0)
  • 2020-12-14 06:32

    If someone needs multiple files pretranspiled before the actual project compiling, use a separate tsconfig with the --project compiler option.

    Compile a project given a valid configuration file. The argument can be a file path to a valid JSON configuration file, or a directory path to a directory containing a tsconfig.json file. See tsconfig.json documentation for more details.

    One use case would be the need of the resulting JS files used afterwards in command line arguments for ionic app scripts.

    0 讨论(0)
  • 2020-12-14 06:39

    In case anyone needs this for Mac OS X:

    find . -name "*.ts" -type f >ts-files.txt
    /usr/local/bin/tsc @ts-files.txt --module CommonJS --out ./Deploy/ServerMain.js --removeComments
    rm ts-files.txt
    
    0 讨论(0)
提交回复
热议问题