Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make babel exclude test files

On my build step I'm using babel to transpile the code to es5 (from src to dist). How do I make it exclude files ending in .test.js?

package.json

"scripts": {   "build": "babel src --out-dir dist", 

.babelrc

{   "presets": [ "es2015" ],   "ignore": "\\.test\\.js" } 
like image 703
Manuel Avatar asked Feb 15 '16 17:02

Manuel


People also ask

What is a .babelrc file?

The . babelrc file is your local configuration for your code in your project. Generally you would put it in the root of your application repo. It will affect all files that Babel processes that are in the same directory or in sibling directories of the . babelrc .

What is babel choose the correct option?

Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments.

What is babel preset ENV?

@babel/preset-env is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s). This both makes your life easier and JavaScript bundles smaller!


2 Answers

Based on the documentation, you should be able to write .babelrc

{   "ignore": [     "**/*.test.js"   ] } 

However, I was able to verify that this does not seem to work. I tried it with version 6.5.1 (babel-core 6.5.2).

At the same time, the following does work:

babel src --out-dir build --ignore '**/*.test.js' 

That is the same glob pattern as written in the .babelrc file. If you install any glob library from npm you'll find that this glob pattern would work (that is how I came up with it...I do not currently use babel).

like image 182
Wil Moore III Avatar answered Sep 16 '22 18:09

Wil Moore III


As of today, the following works in .babelrc (babel-core: v6.26.3)

"ignore": [   "**/__tests__", // ignore the whole test directory   "**/*.test.js" // ignore test files only ] 
like image 43
Pubudu Dodangoda Avatar answered Sep 17 '22 18:09

Pubudu Dodangoda