dimanche 4 juin 2017

`mocha --compilers js:babel/register` only for some files, but not others?

I have a full-stack app with a React/Redux front end, and Node/Sequelize/Express backend. My development (watch) test script is as follows:

"test": "mocha --compilers js:babel-register --watch-extensions js,jsx app/**/*.test.js app/**/*.test.jsx server/**/*.test.js db/**/*.test.js",
"test-watch": "npm run test -- --watch --reporter=min",

The problem with this is that it applies babel transpilation not only to the front end code, as desired, but also the backend code. That's an issue because it chokes on async/await syntax, which is supported natively by the Node version the server will run on. There are ways to augment the Babel transpiler to polyfill async/await, but that is adding complexity and seems like throwing good money after bad.

Is there any way to specify that compilers should be used for certain files, and not others? I'd even base it off of extension (jsx vs js) if necessary.

Another thing I know I could do is two separate Mocha processes, which could then be combined in my development script, but again that's making things more complex… I just want to be able to selectively transpile. Hoping this is supported.

Aucun commentaire:

Enregistrer un commentaire