brunch / deppack

Extract node modules to browser.
MIT License
4 stars 13 forks source link

Change deppack to an initializable class instead of "exports" object #16

Closed paulmillr closed 8 years ago

paulmillr commented 8 years ago

Feels weird the current way.

paulmillr commented 8 years ago

@goshakkk

goshacmd commented 8 years ago

@paulmillr what do you think about something like

const bindToDeppack = (fnName) => {
  return function() {
    if (!deppack) return;
    return deppack[fnName].apply(deppack, arguments);
  };
};

['exploreDeps', 'processFiles', 'wrapInModule', 'needsProcessing', 'isNpm', 'isNpmJSON', 'isShim', 'getAllDependents'].forEach(fnName => {
  exports[fnName] = bindToDeppack(fnName);
});

exports.loadInit = (config, json) => {
  deppack = config.npm.enabled ? new Deppack(config, json) : new NoDeppack();
  return deppack.init();
};

to achieve the desired result (aka being able to import only the needed function and call it from brunch)

paulmillr commented 8 years ago

Still doesn't work when there are >1 deppacks.

goshacmd commented 8 years ago

There's never more than one at any given point.