1.0.5 • Published 2 years ago

react-native-absolute-imports v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

react-native-absolute-imports

Version NPM

react-native-absolute-imports configures your react-native project to support absolute imports like in web react project

✅ Use import like this

import store from 'store'
import moduleAStore from 'modules/moduleA/store'
import ComponentA from 'modules/moduleA/ComponentA'
import Avatar from 'components/ui/Avatar'

❌ Not this

import store from '../store'
import moduleAStore from '../../../modules/moduleA/store'
import ComponentA from '../../../modules/moduleA/ComponentA'
import Avatar from '../../../../../../components/ui/Avatar'

Installation

from npm

npm install --save-dev react-native-absolute-imports

from yarn

yarn add -D react-native-absolute-imports

Configuring

You need also install babel-plugin-module-resolver

from npm

npm install --save-dev babel-plugin-module-resolver

from yarn

yarn add --dev babel-plugin-module-resolver

Change your babel.config.js file

const setupAbsoluteImports = require('react-native-absolute-imports');

const alias = setupAbsoluteImports({tsEnabled: true, srcDirName: 'src'});

module.exports = {
  plugins: [
    [
      'module-resolver',
      {
        alias,
      },
    ],
  ],
};

Run metro with cache clearing

❗Run metro with cache clearing always when you change (renaming,removing, adding) top level directories in your source directory

  yarn start --reset-cache

✅ All done

Properties

PropDefaultTypeDescription
srcDirName-string(required)Specify your source directiory
tsEnabledfalseboolSpecify if your project configured with typescript
1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago