1. 程式人生 > 其它 >VUE專案中的sconfig.json詳解

VUE專案中的sconfig.json詳解

vue專案中使用TypeScript時專案中會自動生成一個tsconfig.json檔案

tsconfig.json 是用於配置TypeScript 編譯時的配置選項

常用的配置如下:

{
  "compilerOptions": {
    // 目的碼(ts -> js(es5/6/7))
    "target": "esnext",
    // 目的碼需要使用的模組化方案(commonjs require/module.exports/es module import/export)
    "module": "esnext",
    // 嚴格一些嚴格的檢查(any)
    "strict": true,
    // 對jsx進行怎麼樣的處理
    "jsx": "preserve",
    // 輔助的匯入功能
    "importHelpers": true,
    // 按照node的方式去解析模組 import "/index.node"
    "moduleResolution": "node",
    // 跳過一些庫的型別檢測 (axios -> 型別/ lodash -> @types/lodash / 其他的第三方)
    // import { Person } from 'axios'
    "skipLibCheck": true,
    // export default/module.exports = {}
    // es module 和 commonjs
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    // 要不要生成對映檔案(ts -> js)
    "sourceMap": true,
    // 檔案路徑在解析時, 基本url
    "baseUrl": ".",
    // 指定具體要解析使用的型別
    "types": ["webpack-env"],
    // 路徑解析(類似於webpack alias)
    "paths": {
      "@/*": ["src/*"],
      "components/*": ["src/components/*"]
    },
    // 可以指定在專案中可以使用哪裡庫的型別(Proxy/Window/Document)
    "lib": ["esnext", "dom", "dom.iterable", "scripthost"]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": ["node_modules"]
}