首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在react本机中使用babel.config.js中的依赖项?

如何在react本机中使用babel.config.js中的依赖项?
EN

Stack Overflow用户
提问于 2022-01-18 18:48:10
回答 1查看 409关注 0票数 0

我有一个依赖,我想回避我的反应-本土项目。目前,我的babel.config.js文件中有以下代码:

代码语言:javascript
复制
module.exports = function (api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      
    ],
  };
};

我已经找到了扩展babel-plugin-module-resolver,它似乎很有用(任何其他的选择也可以),并试图跟随他们的例子,但它们没有工作

我试过以下几种方法:

代码语言:javascript
复制
module.exports = function (api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      [
        'module-resolver',
        {
          root: ["./src"],
          alias: {
            '@dependency/to-shim': 'path/to-shimmer',
          },
        },
      ],
    ],
  };
};

但这不起作用

EN

回答 1

Stack Overflow用户

发布于 2022-08-05 19:49:19

我也有同样的错误。运行时代码正常工作。问题在于建造。这条路仍然是绝对的。

babel.config.js

代码语言:javascript
复制
module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    [
      'module-resolver',
      {
        root: ['.'],
        alias: {
          '@services': './src/services',
        },
      },
    ],
    'react-native-reanimated/plugin',
  ],
};

tsconfig.json

代码语言:javascript
复制
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@services*": ["./src/services"]
    },
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "esModuleInterop": true,
    "importsNotUsedAsValues": "error",
    "forceConsistentCasingInFileNames": true,
    "jsx": "react",
    "lib": ["esnext"],
    "moduleResolution": "node",
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noImplicitUseStrict": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strict": false,
    "target": "esnext"
  },
  "include": ["src"],
  "exclude": [
    "node_modules",
    "commitlint.config.js",
    "metro.config.js",
    "jest.config.js",
    "babel.config.js"
  ]
}

截图-在构建后应该是相对的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70760883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档