admin管理员组文章数量:1323023
Is there a babel
plugin to avoid long import path in CRA?
I've searching a lot on the web but I can't find the best way to achieve this.
Actual:
import MyComponent from '../../../../ponents/MyComponent'
Expected
import MyComponent from 'ponents/MyComponent'
Is there a babel
plugin to avoid long import path in CRA?
I've searching a lot on the web but I can't find the best way to achieve this.
Actual:
import MyComponent from '../../../../ponents/MyComponent'
Expected
import MyComponent from 'ponents/MyComponent'
Share
Improve this question
edited Dec 2, 2019 at 22:36
Emile Bergeron
17.4k5 gold badges85 silver badges131 bronze badges
asked Dec 2, 2019 at 21:34
tolotratolotra
3,2701 gold badge12 silver badges19 bronze badges
1 Answer
Reset to default 12In your main root, create file jsconfig.json
:
{
"pilerOptions": {
"baseUrl": "src"
},
"include": ["src"]
}
Where src
is the folder where you store your project files, sometimes it may be /app
or /src
.
Then you will be able to import your ponents with an absolute path:
import MyComponent from 'ponents/MyComponent';
本文标签:
版权声明:本文标题:javascript - How to avoid very long paths and use absolute paths within a Create React App project? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742111021a2421254.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论