mardi 25 octobre 2016

Building Javascript Modules

I have small library for client side routing and template loading. It's built from several smaller module, for example Tpl, Router..

Every module check if library namespace is defined and than apply itself to it.

Here is the code: http://ift.tt/2eFALRB

For example Tpl component binds itself to Micro library (the main lib)

if(typeof Micro === "function" && Micro.prototype.isMicro){
      Micro['Tpl'] = Tpl;

And that I am calling library with constructor

var micro = new Micro(properties);

Problem is if I want to make another instance...dependencies will collide internally

var micro2 = new Micro2(properties);

For build, I use gulp and just concatenate modules to one file..

Can anyone propose a good way to build multiple modules to one, like sandboxing them? Or some best practices and patterns without using webpack, requireJs etc..

Aucun commentaire:

Enregistrer un commentaire