Mocha: Custom path of babel.config (for babel-register) ?

Created on 13 Jul 2019  路  4Comments  路  Source: mochajs/mocha

mocha test.js --require=@babel/register
  • scripts/babel.config.js
  • package.json

How can I get this to work without adding a new file or moving my Babel config?

question

Most helpful comment

@stevenvachon you may need a new file to load babel and specify the config value, see below. AFAIK there is no way to pass a babel cli option from mocha cli directly.

mocha config

require: 'scripts/register-babel.js'

scripts/register-babel.js

require("@babel/register")({
  configFile: "./scripts/babel.config.js"
});

Does that help?

All 4 comments

What version of mocha/babel etc?

How does your app point to that babel config? Does that work?

Any reason you did not want to place the config in root (or package.json), which i believe is the recommended approach?

  • @babel-core v7.5.0
  • mocha v6.1.3
"scripts": {
  "build": "babel lib/ --config-file=./scripts/babel.config.js --out-dir=lib-cjs/ --source-maps"
}

I prefer not to have too many files in the project root.

@stevenvachon you may need a new file to load babel and specify the config value, see below. AFAIK there is no way to pass a babel cli option from mocha cli directly.

mocha config

require: 'scripts/register-babel.js'

scripts/register-babel.js

require("@babel/register")({
  configFile: "./scripts/babel.config.js"
});

Does that help?

Does that help?

Yup! Thanks!

I didn't use a mocha config file, though; instead opting for the --require CLI option.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

luoxi001713 picture luoxi001713  路  3Comments

enigmatic00 picture enigmatic00  路  3Comments

danielserrao picture danielserrao  路  3Comments

robertherber picture robertherber  路  3Comments

jamietre picture jamietre  路  3Comments