美文网首页
Typescript 编译配置

Typescript 编译配置

作者: Amy_yqh | 来源:发表于2023-03-04 15:14 被阅读0次

    1、include

    用来指定哪些ts文件需要被编译
     路径:**表示任意目录
          *表示任意文件
    {
        "include": [
            "src/**/*"
        ],
    }
    

    2、exclude

    不需要被编译的文件目录
    默认值【"node_modules","bower_comonents","jspm_packages"】
    {
      "exclude": ["./src/hello/**/*"],
    }
    

    3、extends

    定义被继承的配置文件
    {
      "extends":"./config/base.json".
    }
    

    4、files

    指定被编译文件的列表,只有需要编译的文件少时才会使用
       "files": [
          "core.ts",
          "sys.ts"
       ],
    

    5、target

     设置ts代码编译的目标版本
     可选值:ES3(默认),ES5,ES6/ES2015、ES7/ES2016、ES2017、
    ES2018、ES2019、ES2020、ESNext
    {
      "compilerOptions":{
         "target": "ES2015",
      }
    }   
        
    

    6、module

    设置编译后代码使用的模块化系统
    可选值:None、CommonJS、UMD、AMD、System、ESNEXT
    {
      "compilerOptions":{
          "module": "amd",
      }
    }  
    

    7、lib

    指定代码运行时所包含的库(宿主环境)
    {
      "compilerOptions":{
          "lib": ["DOM","ES6"],
      }
    }  
    

    8、outDir

    用来指定编译后文件所在目录
    {
      "compilerOptions":{
         "outDir": "./dist",
      }
    }  
    

    9、outFile

    将代码合并为一个文件,使用该属性,modeule必须有system或者amd
    {
      "compilerOptions":{
         "outFile": "./dist/app.js"
      }
    }  
    

    10、allowJs

    是否对js文件进行编译,默认为false,有些模块可能是用js写的
    {
      "compilerOptions":{
          "allowJs": true,
      }
    }  
    

    11、checkJs

    检查js代码是否符合语法规范,默认为false
    {
      "compilerOptions":{
        "checkJs": true,
      }
    }  
    

    12、removeComments

     编译后的文件是否移除注释
    {
      "compilerOptions":{
        "removeComments": true,
      }
    }  
    

    13、noEmit

     不生成编译后的文件(一般用在只检查ts语法,不生成js文件)
    {
      "compilerOptions":{
          "noEmit": false,
      }
    }  
    

    14、noEmitOnError

    当有错误时,不生成编译文件
    {
      "compilerOptions":{
        "noEmitOnError": true
      }
    }  
    

    9、outFile

    将代码合并为一个文件,使用该属性,modeule必须有system或者amd
    {
      "compilerOptions":{
         "outFile": "./dist/app.js"
      }
    }  
    
           "allowJs": true,
            // 检查js代码是否符合语法规范,默认为false
            "checkJs": true,
            // 编译后的文件是否移除注释
            "removeComments": true,
            // 不生成编译后的文件(一般用在只检查ts语法,不生成js文件)
            "noEmit": false,
            // 当有错误时,不生成编译文件
            "noEmitOnError": true,
            // 严格模式的总开关
            "strict": true,
            // 用来设置编译后的文件释放使用严格模式(编译后的js文件出现"use strict";
    【除文件使用import外】)
            "alwaysStrict": true,
            // 不允许隐式的any
            "noImplicitAny": true,
            // 不允许隐式的this
            "noImplicitThis": true,
            // 严格检查空值

    相关文章

      网友评论

          本文标题:Typescript 编译配置

          本文链接:https://www.haomeiwen.com/subject/noifldtx.html