Is there a way for aliases to “require” paths with React Native packager?

I am looking for a way for aliases using React Native, and not something like:

require('../../blah')

I could do:

require('src/blah') 

where 'src' is at the root of the directory.

+4
source share
3 answers

You can always use your application name as root. (the name that is written in yours package.json):

require('<package name>/img/yourimage.png') 
+2
source

+1 I also need this feature.

I am currently using a browser to associate js files with the response-native label as external and use the aliasify module for path aliases. As a second step, I pass my package to package.

, , - node_modules (, ).

...

0

You can use the pragma fbjs @providesModule. Basically adding the source file:

/**
 * @providesModule blah
 */

It allows you require('blah')to other files.

AFAIK, this feature should only be used for Facebook so that it can trigger warnings or interrupt in the future.

0
source

Source: https://habr.com/ru/post/1608022/


All Articles