3

I'm trying to use an additional babel plugin when running Ava to transpile react dynamic imports so they can run on node (based on this response)

ava dynamic syntax import enable support

I cannot add it to my main .babelrc file as we are implementing bundle splitting in webpack.

To get around this I'm trying to include the plugin through ava's babel configuration. When I run ava, babel does not use the additional plugin.

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

1 Answers1

1

0.24 is quite old. The latest version for Babel 6 is 0.25, but if possible you should upgrade to Babel 7 and use the latest AVA 1.0 beta.

Mark Wubben
  • 3,329
  • 1
  • 19
  • 16