BUPTlhuanyu / react-music-lhy

基于react16+ react-router4+ typescript react-redux的移动端音乐播放器

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

别名设置无效

duriann opened this issue · comments

你好,我按照文中所述分别设置了paths,alias,tsconfig后依然无法使用别名。。
paths.js:
componentPath: resolveApp('src/app/components')
tsconfig.json:
"baseUrl": "src", "paths": { "src/*":["src/*"], "components/*":["src/app/components/*"] },
webpack.config.js
'components': paths.componentPath

报错:
Cannot find module 'components/home/index'. TS2307

我发现了 那个baseUrl 我设置的时候提示我只能写'src'或者'node_modules' 于是我写了个'src'
你的配置中写的是'.' 我改成'.' 成功了 这是什么原理?

最新版create-react-app是推荐写src的,并且已经不需要在webpack.config.js中配置alias,直接在tsconfig中配置即可,新版的reactc li将tsconfig中的baseurl添加到了resolve.modules中。建议按照新版create-react-app的要求将本项目的baseurl写成src,那么tsconfig以及alias也要相应的改变。

已经完善别名配置笔记,ts项目无需在alias中添加别名配置,在tsconfig中写即可