In Node.js, you can dynamically "require()" any javascript file likewise to PHP's require. I'd like to use this in my client-side code just for ease of development but not actually call a javascript function, but have a compiler replace the line with the contents of the respective file; effectively concatenating the files, not one after another, but inline within the code of one of the files. The closest thing I have found to this is smash. Are there any compilers, minifiers, etc that can do this?
Asked
Active
Viewed 455 times
1
-
You could do it on request with php or node.js, then you wouldn't have to recompile every time you update the js files – PitaJ Apr 11 '14 at 16:09
-
Related: http://stackoverflow.com/questions/868857/combining-and-compressing-multiple-javascript-files-in-php – PitaJ Apr 11 '14 at 16:14
-
Also related: http://stackoverflow.com/questions/6539837/concat-and-minify-js-files-in-node – PitaJ Apr 11 '14 at 16:18
-
@PitaJ Not looking for a dynamic solution with PHP or Node.js. I'm working on a library so I have to compile it to release it -- I'm not actually serving the file. And, not related -- those solutions are concatenating files sequentially, which is not what I'm looking for. – Hiroki Osame Apr 11 '14 at 16:21
-
Well if that is what you want, you'll probably have to write it yourself. It shouldn't be too difficult. And those links are related because with a little modification they could do what you want. – PitaJ Apr 11 '14 at 16:23
-
@PitaJ Came here to save me the work; that is my last resort. Thanks for trying to help, though. Hopefully someone knows of a software that can do what I'm looking for. – Hiroki Osame Apr 11 '14 at 16:30
-
Sounds a lot like something an ant task could do. or grunt. – Kevin B Apr 11 '14 at 21:15
-
@KevinB Yeah, I've looked through Grunt plugins but to me it looks like Smash is the only one that does this kind of thing. – Hiroki Osame Apr 11 '14 at 22:25
-
I would write something myself but sadly I don't have that kind of time on my hands. – PitaJ Apr 14 '14 at 05:29
1 Answers
0
Browserify might not be exactly what you want but it does definitely help with the ease of development issue. When you use Browserify, your code is your build tool. Browserify gives you all the benefits of writing code in node (no anon functions to avoid globals, npm, simple requires, imports instead of namespaced globals) and it allows you to package that code to run on the client with one command and only load one file.
You can checkout my open source js framework Luc JS for an example. It runs on node and IE6. I'm able keep the code modular and build the single browser file with a one line command.

pllee
- 3,909
- 2
- 30
- 33