gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 00:32:42 27 4
gpt4 key购买 nike

我添加了一个 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com