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

ava dynamic syntax import enable support

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

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

package.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"]
}

最佳答案

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

10-08 02:12