相对路径可一般跳转
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/*"]
}
}
}
参考地点: