8

I have front-end JS files:

-js
  -a.js
  -b.js
  -c.js

and I request http://example.com/js/all.js, I will get a file with all contents of a.js, b.js and c.js.

Is there any library provides such function in NodeJS?

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Kevin
  • 1,147
  • 11
  • 21

3 Answers3

2

You may use simple linux cat to concatenate all scripts into one.

cat ./a.js ./b.js ./c.js > all.js

Also you can execute this command from node.js.

Concatenating scripts to all.js with node.js (on air) not the best way because this will increase the server load.

Vadim Baryshev
  • 25,689
  • 4
  • 56
  • 48
2

require.js should offer the functionality you're looking for if the node common.js isn't enough.

djlumley
  • 2,955
  • 2
  • 24
  • 30
2

You should check out anvil: https://github.com/arobson/anvil.js

It offers a highly configurable process for preparing a number of front end files, although I can't seem to find an API that can be used directly from your node application.

Jørgen
  • 8,820
  • 9
  • 47
  • 67