最近在写 React Native,把遇到的东西小记一下。后面遇到的再在这里补充。

babel 插件

  1. babel-plugin-root-import
    配合 tsconfig 给文件夹起别名。

    1. 安装 babel-plugin-root-import
      yarn add -D babel-plugin-root-import

    2. 配置 babel.config.js

      // babel.config.js
      module.exports = function (api) {
        api.cache(true);
        return {
          //... 其他配置
          plugins: [
            // 其他插件
            // ---start---
            [
              'babel-plugin-root-import',
              {
                paths: [
                  {
                    rootPathSuffix: './src',
                    rootPathPrefix: '@/',
                  },
                  // 其他别名
                ],
              },
            ],
            // ---end---
          ],
        };
      };
      
    3. 配置 tsconfig.json

      // tsconfig.json
      {
        // 其他配置
        "compilerOptions": {
          // 其他配置
          // ---start---
          "paths": {
            "@/*": [
              "src/*"
            ],
            // 其他别名
          }
          // ---end---
        },
      }

React Native 组件

组件库:

组件:

其他工具