AO1*_*O17 6 javascript reactjs webpack visual-studio-code
我希望我的项目包含 Webpack resolve.alias 选项,因此我将其添加到我的 webpack.common.js 配置文件中。
一开始我遇到了很多问题,但在搜索网络和许多 GitHub Issues 后,我发现了一些可以帮助我解决问题的帖子。
导入工作正常,但我的问题是 Visual Studios IntelliSense 无法使用我声明的别名。我的设置:
我的项目目录:
+src
-first
-second
+third
| -third-one
| -third-two
| +third-three
| -third-three-one
-jsconfig.json
-.babelrc
-.eslintrc
-webpack.common.js
Run Code Online (Sandbox Code Playgroud)
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'),
},
},
...
Run Code Online (Sandbox Code Playgroud)
.babelrc
{
"presets": ["es2015", "react", "airbnb"],
"plugins": [
["module-resolver", {
"alias": {
"first": "./first",
"second": "./second",
"third": "./third",
"common": "./third/third-three/third-three-one"
}
}]
]
}
Run Code Online (Sandbox Code Playgroud)
jsconfig.json
...
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"first": ["./first"],
"second": ["./second"],
"third": ["./third"],
"common": ["./third/third-three/third-three-one"],
}
},
...
Run Code Online (Sandbox Code Playgroud)
.eslintrc
...
"settings": {
"import/resolver": {
"webpack": {
"config": "webpack.common.js"
},
"babel-module": {
"extensions": [".js", ".jsx"]
}
}
},
...
Run Code Online (Sandbox Code Playgroud)
对于这种情况,我安装了重要的 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",
Run Code Online (Sandbox Code Playgroud)
VS代码:1.20
Windows 10
有谁知道缺少什么?为什么 IntelliSense 没有触发?
尝试将 jsconfig 更改为:
"compilerOptions": {
...
"baseUrl": "./",
"paths": {
"first/*": ["./first/*"],
"second/*": ["./second/*"],
"third/*": ["./third/*"],
"common/*": ["./third/third-three/third-three-one/*"],
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道到底为什么,但没有星星,它对我不起作用。
归档时间: |
|
查看次数: |
4411 次 |
最近记录: |