为什么我没有得到 babeljs 的导入建议

Why I don't get import suggestions with babeljs

我正在使用带有 vscode 和 yarn 工作区的 babel-env 以及加载包时(编译后)。

我没有得到任何关于导入自动完成的建议..

我的项目结构:

|--packages
| |--common
|    |--src
|    |--dist
|    |--.babelrc
| |--server
|    |--src
|    |--dist
|    |--.babelrc
| |--web(create-react-app default settings)

babelrc 设置:

{
  "presets": ["@babel/preset-env"]
}

构建命令:

rm -rf dist && babel ./src --out-dir dist --copy-files

导入用法示例:

import { validation, functions } from "@project/common";

然后当我输入 exmaple 时 validation.inputs 我没有收到任何建议..

也许我需要添加一些 babel 扩展,我在文档中搜索但一无所获。

感谢您的帮助。

尝试将 es6 功能添加到您的工作区。所以在你的 jsconfig.json 添加这个:

{
    "compilerOptions": {
        "target": "es6"
    },
    "exclude": [
        "node_modules"
    ]
}

在 package.json 我补充说:

  "types": "./index.d.ts",
  "files": [
    "index.d.ts"
  ],

我在公共根文件夹中添加了文件:"index.d.ts" 其中包含

export { default } from "./src/index";
export * from "./src/index";

我不知道你是否需要这样做,但它解决了我的问题