2

Is there anyway to include all *.js files in a directory to be combined and minified using Google's Closure Compiler?

The only way I know of is listing each file individually:

java -jar compiler.jar --js 1.js --js 2.js  --js_output_file app-min.js

but in an enterprise app, this is not feasible.

Thanks

stackato
  • 1,085
  • 1
  • 19
  • 38

2 Answers2

4

The compiler uses java style globs:

  • --js src/*.js - all js files in the src folder
  • --js src/**.js - all js files in the src folder and any sub folders (recursive)
  • --js !src/**test.js - exclude files that end in with "test.js" (recursive)

Order matters.

However, you will need some method to determine the correct order. See https://github.com/google/closure-compiler/wiki/Manage-Closure-Dependencies

Chad Killingsworth
  • 14,360
  • 2
  • 34
  • 57
  • this works. but now i need to figure out how to EXCLUDE some files from that directory... I shoudlve been more clear with my question. – stackato Jan 08 '16 at 19:30
  • What about `--js controller/**/*.js`. I excpected it to take all js file under controller AND all other of it sub floders; no matter how deep. It works fine on windows, but on linux only files under a direct subfolder of controller are taken like if I wrot `--js controller/*/*.js ` – Bancarel Valentin May 22 '18 at 08:41
  • Ok, I found out you **should not** forget the simple quotes. I end uploosing time because of this. Without them, it works on windows; not on linux. – Bancarel Valentin May 22 '18 at 09:10
1

A similar question has been previously ask, please see this post

Compress all file .js with Google Closure Compiler Application in one File

But you might want to be careful with any method that auto-appends files in a directory and send them off to the Closure compiler, so the right order for compilation of your scripts is maintained

Community
  • 1
  • 1