0

I want to transpile JS files in a folder recursively and overwrite the same files with transpiled JS.

babel build/sample.js --out-file build/sample.js

Using the above command, I can transpile a single file. How could I do this recursively over a folder?

Edit:

  • I don't want to use Webpack.

  • My Source code will be in a different folder 'A' (with js.php files). And I use a PHP build process to generate a build folder 'B' (with .js files). I want to apply Babel on folder 'B' after generating the build folder.

  • I can't afford the time to make changes on to run Babel before the PHP build process now.

Gugan
  • 1,625
  • 2
  • 27
  • 65
  • 1
    Using bash? `for x in directory/*.js ; do babel "$x" --out-file "$x" ; done` – Kelvin Sherlock Nov 12 '18 at 21:27
  • 1
    you'll lose all the original code. IMHO you should send the output to a separate directory. if your goal is to make an NPM package out of it, you can specify which files to include and exclude, and keep both the pre-and-post-transpiled code. – Derek Nov 12 '18 at 21:28
  • 1
    What is the motivation for placing them in the same location? That seems like an immediate problem, irrespective of whether it is technically possible. – loganfsmyth Nov 12 '18 at 21:41
  • My Source code will be in a different folder 'A'. And I use a PHP build process to generate a build folder 'B'. I want to apply Babel on folder 'B' after generating the build folder. My bad, I didn't explain this clearly. – Gugan Nov 12 '18 at 21:44

0 Answers0