最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to avoid very long paths and use absolute paths within a Create React App project? - Stack Overflow

programmeradmin4浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 12

In 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';

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论