3

我正在尝试在运行 Ava 时使用额外的 babel 插件来转换反应动态导入,以便它们可以在节点上运行(基于此响应)

ava 动态语法导入启用支持

我无法将它添加到我的主 .babelrc 文件中,因为我们正在 webpack 中实现捆绑拆分。

为了解决这个问题,我试图通过 ava 的 babel 配置包含插件。当我运行 ava 时,babel 不使用附加插件。

包.json

{
  "dependencies": {
    "babel-cli": "6.16.0",
    "babel-core": "^6.26.3",
    "babel-eslint": "7.2.1",
    "babel-loader": "^7.1.2",
    "babel-plugin-dynamic-import-node": "^2.1.0",
    "babel-plugin-flow-react-proptypes": "^5.1.2",
    "babel-plugin-module-resolver": "^2.7.1",
    "babel-plugin-recharts": "1.1.0",
    "babel-plugin-syntax-dynamic-import": "^6.18.0",
    "babel-plugin-transform-async-to-generator": "^6.22.0",
    "babel-plugin-transform-builtin-extend": "^1.1.2",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-flow-strip-types": "^6.22.0",
    "babel-plugin-transform-object-rest-spread": "^6.22.0",
    "babel-polyfill": "^6.23.0",
    "babel-preset-es2015": "6.16.0",
    "babel-preset-es2015-node": "^6.1.1",
    "babel-preset-react": "6.16.0"
  },
  "devDependencies": {
    "ava": "^0.24.0",
    "babel-preset-env": "^1.7.0",
    "babel-register": "6.16.3"
  },
  "ava": {
    "require": [
      "babel-register",
      "babel-polyfill",
      "ignore-styles"
    ],
    "babel": {
      "plugins": [
        "babel-plugin-dynamic-import-node"
      ]
    }
  }
}

.babelrc

{
  "plugins": [
    ["babel-plugin-transform-builtin-extend", {
      "globals": ["Error"]
    }],
    "recharts",
    "transform-object-rest-spread",
    "flow-react-proptypes",
    "transform-flow-strip-types",
    "transform-async-to-generator",
    "transform-class-properties",
    "syntax-dynamic-import",
    "react-hot-loader/babel",
    [
      "module-resolver",
      {
        "root": ["./src"],
        "alias": {
          "tests": "./tests"
        }
      }
    ]
  ],
  "presets": ["env", "react"]
}
4

1 回答 1

1

0.24很老了。Babel 6 的最新版本是0.25,但如果可能,您应该升级到 Babel 7 并使用最新的 AVA 1.0 beta。

于 2018-09-12T08:26:49.863 回答