【问题标题】:Configuring for babel.config.js为 babel.config.js 配置
【发布时间】:2019-05-27 04:16:19
【问题描述】:

我对 Expo 和 React Native 比较陌生。在导入模块时一直面临使用绝对路径的问题。正在阅读如何实现这个插件,但我无法正确使用它,因为它只有 .babelrc 的说明。我做了几乎所有在不同线程上发现的事情,但我仍然无法正确使用它。在我的世博项目中,我也没有任何.babelrc 文件,而是有babel.config.js 文件。

我正在尝试将此代码转换为.babelrc

{
  "presets": ["babel-preset-expo"],
  "env": {
    "development": {
      "plugins": [
        "transform-react-jsx-source",
        ["module-resolver", {
          "root": ["./src"]
        }]
      ]
    }
  }
}

到此为babel.config.js

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
  };
};

谢谢

【问题讨论】:

    标签: react-native babeljs expo


    【解决方案1】:

    检查配置:

    .babelrc

    {
      "extends": "./babel.config.js"
    }
    

    babel.config.js

    module.exports = (api) => {
      api.cache(true)
      return {
        "env": {
          "development": {
            "plugins": [
              "transform-react-jsx-source",
              ["module-resolver", {
                "root": ["./src"]
              }]
            ]
          }
        },
        presets: ['babel-preset-expo']
      }
    }
    

    【讨论】:

    • .babelrc 和 babel.config.js 文件应该放在哪里? babel.config.js 是否需要在任何地方引用/链接?
    • 一般在你项目的根目录下,更多细节请查看官方文档babeljs.io/docs/en/config-files
    猜你喜欢
    • 2023-02-06
    • 2020-06-12
    • 1970-01-01
    • 2020-07-11
    • 2020-06-02
    • 1970-01-01
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    相关资源
    最近更新 更多