Ad

How Do You Setup Static Paths In Javascript?

- 1 answer

This may be a silly question, but I can't seem to find a simple answer via google

Lets say I have a react component library, full of display component, and I want it to be easily included into most of my smart/container components. Because it will be used all over the place, I'd rather not use relative paths from every different component in my app import Component from '../../library/Component' and ../library/Component and ../../../library/Component etc...

How could I set it up so all I had to do was import Component from 'library/Component' wherever in the app I wanted to be?

Asked another way, what is the generally prescribed way to setup static paths in javascript?

Ad

Answer

With webpack you could using way of "several root directories". Builder will find your modules by several paths. And you can write something like this: "./lodash" instead "../../../../lodash". Look this for more info.

Ad
source: stackoverflow.com
Ad