Skip to content

Latest commit

 

History

History
51 lines (43 loc) · 881 Bytes

README.md

File metadata and controls

51 lines (43 loc) · 881 Bytes

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';