处理vscode 开辟react 导入绝对路径 没法跳转的题目

相对路径可一般跳转

import { namespace, getStaffs as actionGetStaffs, addStaffs as actionAddStaffs } from '../../redux/actions/staff'

但是在webpack设置alias运用绝对路径后没法跳转

webpack设置:

resolve: {
       modules: [path.join(__dirname, 'src'), 'node_modules'],
       extensions: ['.js', '.jsx', '.json', '.scss', '.css'],
       alias: {
            src: path.join(__dirname, 'src'),
       },
       plugins: [
            new ModuleScopePlugin(appSrc, [appPackageJson]),
       ],
},

// 文件导入

import { namespace, getStaffs as actionGetStaffs, addStaffs as actionAddStaffs } from 'src/redux/actions/staff'

解决办法:
须要增加一个jsconfig文件,以下:

{
  "compilerOptions": {
    "baseUrl": "./",  // all paths are relative to the baseUrl
    "paths": {
        "src/*" : ["src/*"]   
    }
  }
}

参考地点:

    原文作者:JayChang2017
    原文地址: https://segmentfault.com/a/1190000018597397
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞