如何让VSCode识别当前包的Javascript导入?

时间:2018-02-09 15:56:25

标签: javascript visual-studio-code javascript-intellisense

当我导入像

这样的javascript函数时,VSCode intellisense很棒
import func from './file';

vs code会给我一个有用的对话框,其中包含来自jsdoc的参数。这是因为我正在使用相对文件路径。

但是,如果我正在使用当前的包,我们将其称为“public”,如我的package.json中所列,并尝试使用其绝对路径引用文件,intellisense不会获取文件

// import the same file as above, but using absolute path
// public is the name of the current npm package
import func from 'public/subfolder/file'; 

intellisense不再出现。

这是错误还是配置问题?

1 个答案:

答案 0 :(得分:0)

步骤1

创建一个jsconfig.json文件以指示vs代码中的JavaScript项目,只需转到vs代码的底部并单击绿色灯泡图标。

它会要求您创建jsconfig.json。创建包含以下代码的jsconfig.json文件。

//jsconfig.json
{
 // See https://go.microsoft.com/fwlink/?LinkId=759670
 // for the documentation about the jsconfig.json format
 "compilerOptions": {
 "target": "es6",
 "module": "commonjs",
 "allowSyntheticDefaultImports": true
 },
 "exclude": [
 "node_modules",
 "bower_components",
 "jspm_packages",
 "tmp",
 "temp"
 ]
}

enter image description here

第二步 enter image description here 全局安装打字输入以下载明文,猫鼬,角等节点模块的TypeScript定义文件(打字)。

npm install typings --global

TypeScript定义文件是用TypeScript编写的,为函数及其参数提供VS IntelliSense体验。让我们按照下面的说明安装明文:

typings insall dt~express --global

让我们尝试快递的编码体验。你会看到伟大的表达智能。

enter image description here

相关问题