开发者

Automatically concat several JavaScript files in one?

开发者 https://www.devze.com 2022-12-22 07:37 出处:网络
I have many js files, with some naming convention. If there any tool that concatenate all this files in one, so I开发者_如何学编程 don\'t need to include them all separately ?You could look at using a

I have many js files, with some naming convention. If there any tool that concatenate all this files in one, so I开发者_如何学编程 don't need to include them all separately ?


You could look at using a JS Minifier, like:

  1. http://code.google.com/p/minify/
  2. http://code.google.com/closure/compiler/
  3. http://www.crockford.com/javascript/jsmin.html


Something like:

$> cat file1.js file2.js ... > allfiles.js

?


In bash:

for file in `ls *js` ; do cat "$file" >> outputscript.js; echo >> "$file"; done;


You might find some helpful information here. Several answers advocate creating multiple javascript files during development, just so developers don't go crazy scrolling through thousands of lines of code. Those files are then merged during deployment -- several approaches are suggested. Several respondents also advocate using minification, which can reduce the size of the resulting mega-file.


In addition to the straightforward answers like using cat or a minifier, you can also use Sprockets, which is a JavaScript build system written in Ruby. Prototype JS uses Sprockets (in fact it Sprockets was written for Prototype).

0

精彩评论

暂无评论...
验证码 换一张
取 消