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

本文标签: