在运行摩卡测试时使用不同的babel预设 [英] use different babel preset when running mocha tests
问题描述
我的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屋!