dmitrynikolaev
dmitrynikolaev

Reputation: 9132

Automatically concat several JavaScript files in one?

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 ?

Upvotes: 0

Views: 1409

Answers (5)

Andrew Noyes
Andrew Noyes

Reputation: 5298

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).

Upvotes: 0

DOK
DOK

Reputation: 32831

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.

Upvotes: 0

David Souther
David Souther

Reputation: 8174

In bash:

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

Upvotes: 0

anddoutoi
anddoutoi

Reputation: 10111

Something like:

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

?

Upvotes: 1

Related Questions