javascript - 我的 jsconfig.json 在 Visual Studio Code 中不起作用吗?

标签 javascript visual-studio-code vscode-settings

我添加了一个 jsconfig.json在我的 javascript 项目的根目录中尝试排除一些构建文件以及设置一些路径映射,但似乎没有任何 react 。部分问题是我不确定使用 jsconfig.json 时的预期结果是什么。 , 我读过 documentation对于它,但它没有显示任何结果。
有人可以给我提供一个小而有效的jsconfig.json描述它的实际作用?这样我就可以用它来验证它在我的项目中是否也确实有效。
或者,有人知道验证 jsconfig.json 的方法吗? VS Code 正在工作/拾取?

最佳答案

在我的项目中,我使用 jsconfig.json 文件直接从 ./src 目录从我尝试导入的任何位置访问文件导入。
我的 jsconfig.json 看起来像:

{
    "compilerOptions": {
        "baseUrl": "./src"
     },
     "include": [
         "src"
      ]
}
包括:

If no include attribute is present, then this defaults to including all files in the containing directory and subdirectories. When a include attribute is specified, only those files are included


基本网址:

This gives the base directory for the file import path


这是我使用 jsconfig.json 的项目结构
enter image description here
所以如果我需要从 src/util/auth_util.js 导入一个函数里面 src/component/Login/index.js在 src/component/Login/index.js 里面

src/component/Login/index.js :

import { userLogin } from 'util/auth_util.js'



如果没有使用上面提到的 jsconfig.json 的 import 语句

src/component/Login/index.js :

import { userLogin } from '../../util/auth_util.js'

关于javascript - 我的 jsconfig.json 在 Visual Studio Code 中不起作用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43835694/

相关文章:

javascript - jQuery UI Datepicker 转到日期 URL

JavaScript - 当键可变时如何检查对象是否具有某个键?

visual-studio-code - 如何在 VS Code 中更改 block 关系线颜色

visual-studio-code - 如何在 VS Code 2021 年 4 月正确集成 Cmder?

java - 如何修复 Java UnsupportedClassVersionError

javascript - 为什么只有一个 JavaScript 函数执行 onClick?

javascript - WSO2 脚本中介 : replace function with regex throws exception

java - Maven插件执行失败

json - 关闭VS Code中的最后一个选项卡时如何不关闭编辑器窗口

angular - VS Code 的多个实例