Thursday 15 August 2013

javascript - Include browserify-bundled module with external dependencies on Node.js? -


has bundled a module archive of JavaScript classes in a library using a browser circuit. But I need to define _ and backbone as the global code and would be surprised that this is the best way.

MyLib is mostly a backbone archive, which requires other subdomains:

  var _ = is required ('trash'); Var BABON = Required ('backbone'); If (type window! == 'undefined') BABON. $ = Window $; Var foo = require ('foo'), bar = need ('bar'); Module Exports = backbone.collection.andend ({... my library ...});  

Because the backons and underscores are bigger and more common, do not want to bundle them, but consider them as external dependencies. Therefore, in package.json , I am using browserify-shim to exclude:

  ... "browserify" Module: "Browser-Shim"}, "Browser-Shim": {"Junk": "Global": "Global": {"Transform": "Globally: Backbone"}  

The load in the "backbone" browser is okay, because _ is defined as a global variable:

   

But in node. Js, browser-bundle module looks for these external dependencies in an object named global

  var _ = Is required ("trash"); Var MyLib = Required (". Libs / mylib");   

It fails with TypeError: The method of the undefined can not call 'isEqual' because _ is undefined Mylib.js inside I am looking for:

  var _ = (type window! == "undefined"? Window._: type global =! Defining dependency across the web can work:  
  var _ _ _ _> = GLOBAL.global._ = Required ("Junk"); Var requires MyLib = ( ". / Libs / mylib");  

But this global variable What makes this post very frustrating is:

Is there a better way of adding external dependencies to the Browerify module in Node.js?


No comments:

Post a Comment