jsconfig.json
What is jsconfig.json?
The presence of jsconfig.json
file in a directory indicates that the directory is the root of a JavaScript Project. The jsconfig.json
file specifies the root files and the options for the features provided by the JavaScript language service.
Tip: If you are not using JavaScript, you do not need to worry about
jsconfig.json
.
Tip:
jsconfig.json
is a descendant of tsconfig.json, which is a configuration file for TypeScript.jsconfig.json
istsconfig.json
with"allowJs"
attribute set totrue
.
Why do I need a jsconfig.json file?
Visual Studio Code's JavaScript support can run in two different modes:
-
File Scope - no jsconfig.json: In this mode, JavaScript files opened in Visual Studio Code are treated as independent units. As long as a file
a.js
doesn't reference a fileb.ts
explicitly (either usingimport
or CommonJS modules), there is no common project context between the two files. -
Explicit Project - with jsconfig.json: A JavaScript project is defined via a
jsconfig.json
file. The presence of such a file in a directory indicates that the directory is the root of a JavaScript project. The file itself can optionally list the files belonging to the project, the files to be excluded from the project, as well as compiler options (see below).
The JavaScript experience is improved when you have a jsconfig.json
file in your workspace that defines the project context. For this reason, we offer a hint to create a jsconfig.json
file when you open a JavaScript file in a fresh workspace.
Location of jsconfig.json
We define this part of our code, the client side of our website, as a JavaScript project by creating a jsconfig.json
file. Place the file at the root of your JavaScript code as shown below.
In more complex projects, you may have more than one jsconfig.json
file defined inside a workspace. You will want to do this so that the code in one project is not suggested as IntelliSense to code in another project. Illustrated below is a project with a client
and server
folder, showing two separate JavaScript projects.
Examples
By default the JavaScript language service will analyze and provide IntelliSense for all files in your JavaScript project. You will want to specify which files to exclude or include in order to provide the proper IntelliSense.
Using the "exclude"
property
The exclude
attribute (a glob pattern) tells the language service what files are not part of your source code. This keeps performance at a high level. If IntelliSense is slow, add folders to your exclude
list (VS Code will prompt you to do this if it detects the slow down).
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES6"
},
"exclude": [
"node_modules"
]
}