babeljs - 禁用 .babelrc 继承

标签 babeljs

如何强制 babel 不查看 .babelrc 的父目录?

  • 我有两个 .babelrc文件:./a/.babelrc./a/example/.babelrc .
  • 我在运行 babel./a/example小路。
  • ./a/.babelrc定义了一个插件“lodash”。
  • 我不想在 ./a/example 中执行 babel 时使用这个插件

  • 我试过设置 ./a/example/.babelrc到:
    {
        "stage": 0,
        "plugins": []
    }
    

    但是,正在运行 babel./a/example路径仍然使用“lodash”插件。
    $ pwd
    /a/example
    $ cat ./.babelrc
    {
        "stage": 0,
        "plugins": []
    }
    $ cat ./../.babelrc
    {
        "stage": 0,
        "plugins": [
            "lodash"
        ]
    }
    $ babel ./src/
    Error: ENOENT: no such file or directory, scandir '/a/node_modules/babel-plugin-lodash/node_modules/lodash'
        [..]
    $ babel --babelrc ./.babelrc ./src/
    Error: ENOENT: no such file or directory, scandir '/a/node_modules/babel-plugin-lodash/node_modules/lodash'
        [..]
    

    最佳答案

    有一个未记录的属性叫做 breakConfig .套装breakConfigtrue禁用配置继承。

    这种行为将在 6.x 中改变。在 6.x 中,Babel 将在第一个 .babelrc 处中断它发现。 extends属性将用于显式命名其他 .babelrc要继承的文件。

    关于babeljs - 禁用 .babelrc 继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32540598/

    相关文章:

    node.js - React Webpack 添加新的 npm 包

    ecmascript-6 - 调试器期间未定义 ES6 模块导入

    javascript - 使用 babel 和 webpack 减少转译代码助手

    typescript - 使用 Typescript 和 Electron 还需要 Babel 吗?

    reactjs - "composes"无法使用 babel-plugin-react-css-modules

    javascript - Heroku 上未知的代币传播运算符,在本地工作

    reactjs - 节点模块问题 : Only one default export allowed per module

    javascript - 条件渲染在 React 映射循环中不起作用

    webpack,vue.js, 无法编译vue文件

    javascript - 如何编译导入的ES6 Node 模块?