Skip to content

React Native 相关,Prettier ESLint Redux Rematch使用

Notifications You must be signed in to change notification settings

syanbo/RNPlayground

Repository files navigation

React-Native

设置路径别名支持IDE跳转联想

  • yarn add -D babel-plugin-root-import
  • babel.config.js 添加 plugins
module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    [
      'babel-plugin-root-import',
      {
        paths: [
          {
            rootPathPrefix: '~',
            rootPathSuffix: 'src',
          },
        ],
      },
    ],
  ],
};
  • 在项目根目录下添加jsconfig.json
{
  "compilerOptions": {
    "jsx": "react-native",
    "allowSyntheticDefaultImports": false,
    "experimentalDecorators": true,
    "baseUrl": ".",
    "paths": {
      "~/*": ["src/*"]
    }
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}
  • 在项目中愉快的使用
import env from '~/constants/env';