Is there a way in npm to import a src folder as a module?

Viewed 39

I have a React project with a structure like this:

  • src
    • Components
      • My_component_1
      • My_component_2
    • Images
      • image_1
      • image_2
    • Pages
      • page_1
      • page_2

I'd like to know if exists a way to register a folder as a component (e.g @Images or @Components for all images or components). In this way, if I'm working on sub-component of page 1, I will not need to write:

import component from "../../Components/My_component_1

but

import {My_component_1} from '@Components'

and avoid to manage relative url and different URLs in different components.

2 Answers
Related