javascript - 在 Webstorm 中自动完成我的自定义 npm 模块 (ES6/Babel)

标签 javascript intellij-idea npm ecmascript-6 babeljs

当我使用material-ui时我在 Webstorm 中得到了很好的自动完成功能(ctrl+space):

autocompletion material

我认为这可能与该包包含一个index.es.js 文件有关:

import _AppBar from './AppBar';
export { _AppBar as AppBar };
import _AutoComplete from './AutoComplete';
export { _AutoComplete as AutoComplete };
import _Avatar from './Avatar';
export { _Avatar as Avatar };
import _Badge from './Badge';
export { _Badge as Badge };
import _BottomNavigation from './BottomNavigation';
...

因此,我在自定义 npm 模块中生成了自己的 index.es.js 并将其放在已转换的 index.js 旁边:

import {ActionTypes as _ActionTypesElements} from './reducers/elements/elements';
export { _ActionTypesElements as ActionTypes };

import {ActionTypes as _ActionTypesAppState} from './reducers/appState/appState';
export { _ActionTypesAppState as ActionTypesAppState };

import _appStateActions from './reducers/appState/appState_actions';
export { _appStateActions as appStateActions };
...

但我没有自动完成:

autocomplete me

知道为什么吗?

最佳答案

找到答案:

必须将 jsnext:main 字段添加到 npm 模块的 package.json 中:

package.json:

 ...
 "module": "./index.js",
 "jsnext:main": "./index.es.js",
 ...

Webstorm 识别包的内部导出。

关于javascript - 在 Webstorm 中自动完成我的自定义 npm 模块 (ES6/Babel),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43805725/

相关文章:

node.js - Semaphore CI ruby​​ 项目上的 Javascript (Jest) 测试

javascript - 使用 ".remove()"函数时代码未运行

javascript - 如何从图片中提取图标并显示在页面中? (通过 javascript 或 jquery 或 css)

javascript - 使用给定的数据属性动态创建 JavaScript 值?

java - Intellij Idea 社区无法识别 JUnit Jupiter 的注解 @DisplayName

node.js - npm 命令中 - 和 --(单破折号和双破折号)之间的区别

javascript - 未捕获的类型错误 : Cannot read property 'createMediaElementSource' of null

android-studio - 如何在 Android studio 中导入现有项目时设置 gradle home

intellij-idea - IntelliJ IDEA 部署后 Wildfly 无法加载部署

javascript - Npm 在不同位置 Node js 上安装全局模块