在运行摩卡测试时使用不同的babel预设 [英] use different babel preset when running mocha tests

查看:131
本文介绍了在运行摩卡测试时使用不同的babel预设的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的npm软件包构建使用babel运行,并且我在package.json中使用

My npm package build runs with babel and I configured a babel preset in my package.json with

"babel": { "presets": ["es2015"] }

我还配置了一个摩卡测试脚本

I also configured a mocha test script with

"test": "mocha --compilers js:babel-core/register"

但是,我想使用不同于为构建指定的babel预设运行测试.

However, I would like to run my tests using a different babel preset than that one specified for my build.

有可能吗?我会实现吗?

Is it possible? I would you achieve that?

推荐答案

您可以创建一个名为babel-hook.js的文件并将其放入:

You could create a file named babel-hook.js and put in it:

require("babel-register")({
  presets: [ /* whatever values you want here */ ],
});

然后像这样运行Mocha:

then run Mocha like this:

mocha --require babel-hook

这将注册Babel,您可以使用任何配置选项您想要的它,与package.json中的任何内容分开.

This will register Babel and you can use any configuration option you want with it, separate from anything in package.json.

这篇关于在运行摩卡测试时使用不同的babel预设的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆