Sergio Flores
Sergio Flores

Reputation: 5427

babel-cli transform only files with specific extension

Currently I'm using babel to transpile my JSX wiews via npm run script:

{
  "scripts": {
    "prestart": "npm run transpile-views",
    "start": "node ./src",
    "transpile-views": "babel ./src/views --out-dir ./src/views",
    "lint": "eslint src",
  }
}

I'm using the same directory (src/views) as input and output directory transpiling .jsx files to .js. But when there's already transpiled files in the directory and run again npm run transpile-views babel take all .jsx and .js files.

> [email protected] transpile-views ~/Projects/my-project
> babel ./src/views --out-dir ./src/views

srcviews/AuthView.js -> src/views/AuthView.js
src/views/AuthView.jsx -> src/views/AuthView.js
src/views/HomeView.js -> src/views/HomeView.js
src/views/HomeView.jsx -> src/views/HomeView.js
src/views/MainLayout.js -> src/views/MainLayout.js
src/views/MainLayout.jsx -> src/views/MainLayout.js

Is there a way to specify the extension of input files?

Upvotes: 2

Views: 3683

Answers (1)

Alex Lapa
Alex Lapa

Reputation: 1159

Babel has option -x or --extensions, you can specify:

babel ./src/views -x ".jsx" --out-dir ./src/views

https://babeljs.io/docs/usage/cli/

Upvotes: 4

Related Questions