我希望 VSCode 对 模块路径进行 IntelliSense ,以便我可以通过单击访问它。
例如,在配置 jsconfig.json
之后,我可以通过导入其全局路径来访问 ./src/styled/index
。
但我不知道如何让它与别名一起工作 @styles
// VSCode Intellisene Works
import { mixins, theme } from 'styles';
// VSCode Intellisene Doesn't work
import { mixins, theme } from '@styles';
我当前的 jsconfig.json
:
{
"compilerOptions": {
"baseUrl": "./",
"jsx": "react",
"paths": {
"@styles": ["src/styles/index"]
}
}
}
原文由 Dennis Vash 发布,翻译遵循 CC BY-SA 4.0 许可协议
看来我不得不重新启动 VSCode。
Javascript(
javascript
,javascriptreact
VSCode 中的文件类型)jsconfig.json
文件的一个例子供参考:styles/index
的示例:将允许导入(使用 IntelliSense):
作为奖励:
aliases.js
,这是我用来在webpack
配置文件中定义别名的帮助程序,它有助于避免重复自己,例如,当在storybook
中使用相同的别名时---
以及应用程序本身。打字稿(
typescript
,typescriptreact
文件)在
tsconfig.json
使用compilerOptions.paths
选项,注意路径是相对于baseUrl
:这允许别名(使用 IntelliSense),例如: