gpt4 book ai didi

javascript - Webpack resolve.alias 不适用于 VS Code IntelliSense

转载 作者:行者123 更新时间:2023-11-29 20:57:15 25 4
gpt4 key购买 nike

我希望我的项目包含 Webpack resolve.alias 选项,所以我将它添加到我的 webpack.common.js 配置文件中。

一开始我遇到了很多问题,但在搜索网络和许多 GitHub 问题后,我发现了一些帮助我解决问题的帖子。

导入工作正常,但我的问题是 Visual Studios IntelliSense 无法使用我声明的别名。我的设置:

我的项目目录:

+src
-first
-second
+third
| -third-one
| -third-two
| +third-three
| -third-three-one
-jsconfig.json
-.babelrc
-.eslintrc
-webpack.common.js

webpack.common.js

...
resolve: {
...
alias: {
first: path.resolve(__dirname, './first'),
second: path.resolve(__dirname, './second'),
third: path.resolve(__dirname, './third'),
common: path.resolve(__dirname, './third/third-three/third-three-one'),
},
},
...

.babelrc

{
"presets": ["es2015", "react", "airbnb"],
"plugins": [
["module-resolver", {
"alias": {
"first": "./first",
"second": "./second",
"third": "./third",
"common": "./third/third-three/third-three-one"
}
}]
]
}

jsconfig.json

...
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"first": ["./first"],
"second": ["./second"],
"third": ["./third"],
"common": ["./third/third-three/third-three-one"],
}
},
...

.eslintrc

...
"settings": {
"import/resolver": {
"webpack": {
"config": "webpack.common.js"
},
"babel-module": {
"extensions": [".js", ".jsx"]
}
}
},
...

对于这种情况,我安装的重要 npm 模块:

"webpack": "^2.6.1",
"eslint-import-resolver-babel-module": "^4.0.0",
"eslint-plugin-import": "^2.8.0",
"babel-plugin-module-resolver": "^3.0.0",

VS 代码:1.20

Windows 10

有谁知道缺少什么?为什么 IntelliSense 没有触发?

最佳答案

尝试将 jsconfig 更改为:

"compilerOptions": {
...
"baseUrl": "./",
"paths": {
"first/*": ["./first/*"],
"second/*": ["./second/*"],
"third/*": ["./third/*"],
"common/*": ["./third/third-three/third-three-one/*"],
}
}

我不知道为什么,但没有星号,它对我不起作用。

关于javascript - Webpack resolve.alias 不适用于 VS Code IntelliSense,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48686203/

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