[英]Modify module resolver when using create-react-app
I want to avoid using relative pathing when importing other files. 我想避免在导入其他文件时使用相对路径。 For example, I'd like to change something like:
例如,我想更改以下内容:
import InputBar from ../../pages/InputBar
to import InputBar from components/pages/InputBar
import InputBar from ../../pages/InputBar
import InputBar from components/pages/InputBar
Normally I would modify the resolve options in webpack, but I'm using create-react-app and don't have access to it. 通常,我会修改webpack中的resolve选项,但是我使用的是create-react-app,并且无权访问。
I would like to avoid using npm run eject
. 我想避免使用
npm run eject
。 Is there another way to avoid using relative pathing for imports? 还有另一种方法可以避免对导入使用相对路径吗?
您可以使用rewired ,这将使您可以根据自己的喜好配置react-scripts
,而不必退出CRA。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.