Search code examples
javascriptbabeljs

Babel command line all jsx files in a directory, output as js files


I have been running a command to turn .jsx files into .js files one at a time:

npx babel App.jsx --out-file App.js --plugins=@babel/plugin-transform-react-jsx

I want to do it for everything in a directory. I read through the help command's options and it seems like I should be able to do this

npx babel -d mydirectory -x .jsx  --plugins=@babel/plugin-transform-react-jsx

But that says it requires filenames, despite providing a directory.

What's the right syntax to get this to work?


Solution

  • According to babel docs, it appears the syntax is

    npx babel mydirectory --out-dir dist -x .jsx  --plugins=@babel/plugin-transform-react-jsx
    

    https://babeljs.io/docs/en/babel-cli#compile-directories