umdjs / umd

UMD (Universal Module Definition) patterns for JavaScript modules that work everywhere.
MIT License
7.42k stars 423 forks source link

Examples for multi-file projects #45

Closed abelnation closed 10 years ago

abelnation commented 10 years ago

I have a project that splits functionality into multiple submodules to manage complexity.

Are there patterns for UMD (in my case, global/require/node support) when multiple files are involved?

More specifically, my project creates a namespace for the library with submodules placed within that namespace, e.g. MyModule is the module namespace with MyModule.SubModule1 and MyModule.SubModule2 as submodules.

My specific goal is to be able to concatenate/minify the files into one file to be distributed.

Any ideas? Thanks!

jrburke commented 10 years ago

If the goal is to concate/minify the files for distribution/outside use, then I would not use a UMD pattern for those files. Instead, just choose a format you like and then do the concatenation as you prefer, and perhaps just wrap the concatenated file in a UMD definition.

But for internal, local project use, it is likely easier to just choose a style you prefer internally than to deal with the UMD block for each file, if those individual files are not consumable by the outside world.

Closing as a discussion ticket, feel free to continue discussion here though.

abelnation commented 10 years ago

Super helpful comments, and totally make sense. I guess it get's harder if you want clients of your lib to be able to import specific parts of your lib without importing the whole thing.

For my purposes, your thoughts seem spot on.

I managed to keep my src files clean with the use of a couple of handy grunt tasks: 1) concat src files together 2) indent result file one level 3) wrap with a header and footer (my UMD boilerplate).