Follow

Hmm just concatenating JS files doesn't really work when the order of initialization/execution matters. I can fix that by relying on file name order to concat the files, but then I have less freedom in how I name the files. I can also fix it by creating a single main.js and assembling the rest in a `require()`/#include-style fashion, but then I need to update that file whenever I add/remove a module. Or I can annotate the files with an `//order:123` comment and do some grep/sort magic to concat the files.

So many choices.

@ayo This is why webpack just repeatedly concatenates stuff in order of declared dependencies for each file and leaves optimization to a later time. In many cases that doesn't even happen, leading to morbidly obese files I cannot comfortably open in Emacs.

@wasamasa Yeah, this is a "solved" problem if you're willing to bring in the Node ecosystem and all that cruft, but that's decidedly not KISS.

@ayo But when you include <script>s you need to have the in the right order as well if they depend on one another, so no difference?

If you're using modules though building a dependency graph should be possible though

@minus If I included multiple <script>s, sure, but I moved the problem to my build system by throwing everything into a single file...

@ayo
An order comment sounds like the way to go :P
*winks in LSB*

@ayo I would advise against the order comment. From my point of it is a very bad design to have sorted parts define their "order". The main.js approach looks much simpler and easier to understand to me.

Sign in to participate in the conversation
niu.moe

Welcome to your niu world ! We are a cute and loving international community O(≧▽≦)O !