diff --git a/babel.config.js b/babel.config.js index 21b7ac48c..1d9ebbecf 100644 --- a/babel.config.js +++ b/babel.config.js @@ -5,11 +5,18 @@ // babelrc doesn't respect NODE_PATH anymore but using require does. // Alternative to install them locally in node_modules -module.exports = { - presets: [require("@babel/preset-env"), require("@babel/preset-react"), require("@babel/preset-typescript")], - plugins: [ - [require("@babel/plugin-transform-runtime"), { regenerator: true }], - require("@babel/plugin-proposal-class-properties"), - require("@babel/plugin-proposal-object-rest-spread"), - ], +module.exports = function (api) { + // ensure env is test so that this config won't impact build or dev server + if (api.env("test")) { + return { + presets: [require("@babel/preset-env"), require("@babel/preset-react"), require("@babel/preset-typescript")], + plugins: [ + [require("@babel/plugin-transform-runtime"), { regenerator: true }], + require("@babel/plugin-proposal-class-properties"), + require("@babel/plugin-proposal-object-rest-spread"), + [require("@babel/plugin-transform-modules-commonjs"), { allowTopLevelThis: true }], + ], + }; + } + return {}; };