简体   繁体   中英

How can I minify and concatenate a dir full of JavaScript files?

I'm working on a legacy Ruby on Rails 4 codebase.

It contains hundreds of .js files...

$ find app/assets -name '*.js' | wc -l
  268 

In production mode, it isn't so bad because the Rails Asset Pipeline minifies them and concatenates them into one file.

But in development, page refreshes take an extremely long time.

I don't think they need to load in a specific order, but I'm not 100% sure.

I want to compile (minify and concatenate) only a specific subdir (recursively) of JavaScript files in development mode.

Is there some tool I can point at a dir and output one minified .js file?

Ideally, this would be something that could watch a dir and recompile on changes.

I suspect that maybe Browserify or Webpack might be able to do that, but it isn't obvious to me from the docs how it would work in practice.

You can use Grunt to concat/minfy all your js(or a subset). However, if you update one, you need to recompile manually.

http://gruntjs.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM