jsconfig.json是什么 目录中存在jsconfig.json
文件表示改目录是JavaScript项目的根目录。jsconfig.json
的配置可以对你的文件所在目录下的所有js代码做出个性化支持。 jsconfig.json
是tsconfig.json
的子集。
如果一个目录下存在一个tsconfig.json
文件,那么它意味着这个目录是TypeScript项目的根目录。 tsconfig.json
文件中指定了用来编译这个项目的根文件和编译选项
为什么需要jsconfig.json Visual Studio Code的JavaScript支持可以在两种不同的模式下运行:
文件范围 - 没有jsconfig.json :在此模式下,在Visual Studio Code中打开的JavaScript文件被视为独立单元。 只要文件a.js没有显式引用文件b.ts(使用///引用指令或CommonJS 模块),两个文件之间就没有共同的项目上下文。
显式项目 - 使用jsconfig.json :JavaScript项目是通过jsconfig.json文件定义的。 目录中存在此类文件表示该目录是JavaScript项目的根目录。 文件本身可以选择列出属于项目的文件,要从项目中排除的文件,以及编译器选项(见下文) 在工作空间中定一个jsconfig.json文件时,JavaScript体验会得到改进。
在不使用typescript的时候也可以对js进行ts的类型检查(因为jsconfig.json是tsconfig.json的子集,所以检查是ts的)
当我们在项目中使用了webpack的别名的时候,会发现就没有办法在跳转到相应文件了,此时可以在jsconfig.json中配置
jsconfig.json的配置 可以参考tsconfig.json 的配置文件{ "compilerOptions" : { "target" : "es2015" , "module" : "commonjs" , "checkJs" : false , "baseUrl" : "*" , "paths" : { "@/*" : [ "src/*" ] , "@/components" : [ "src/components" ] , "utils" : [ "src/utils/*" ] } } , "exclude" : [ "node_modules" , "**/node_modules/*" ] , "include" : [ "src/*.js" ] }
compilerOptions 配置项参考"compilerOptions" : { "incremental" : true , "tsBuildInfoFile" : "./buildFile" , "diagnostics" : true , "target" : "ES5" , "module" : "CommonJS" , "outFile" : "./app.js" , "lib" : [ "DOM" , "ES2015" , "ScriptHost" , "ES2019.Array" ] , "allowJS" : true , "checkJs" : true , "outDir" : "./dist" , "rootDir" : "./" , "declaration" : true , "declarationDir" : "./file" , "emitDeclarationOnly" : true , "sourceMap" : true , "inlineSourceMap" : true , "declarationMap" : true , "typeRoots" : [ ] , "types" : [ ] , "removeComments" : true , "noEmit" : true , "noEmitOnError" : true , "noEmitHelpers" : true , "importHelpers" : true , "downlevelIteration" : true , "strict" : true , "alwaysStrict" : true , "noImplicitAny" : true , "strictNullChecks" : true , "strictFunctionTypes" : true , "strictPropertyInitialization" : true , "strictBindCallApply" : true , "noImplicitThis" : true , "noUnusedLocals" : true , "noUnusedParameters" : true , "noFallthroughCasesInSwitch" : true , "noImplicitReturns" : true , "esModuleInterop" : true , "allowUmdGlobalAccess" : true , "moduleResolution" : "node" , "baseUrl" : "./" , "paths" : { "jquery" : [ "node_modules/jquery/dist/jquery.min.js" ] } , "rootDirs" : [ "src" , "out" ] , "listEmittedFiles" : true , "listFiles" : true }
参考文章