javascript - How does the bundle order work in browserify? -


i cannot figure out logic how browserify bundles required files. if this

require('./one/one.js'); require('./two/two.js'); require('./three/three.js'); 

the output this

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new error("cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ var app = "app";  console.log(one); },{}],2:[function(require,module,exports){ require('./one/one.js'); require('./two/two.js'); require('./three/three.js'); //require('./three/three_a/three_a.js'); require('./app.js'); },{"./app.js":1,"./one/one.js":3,"./three/three.js":4,"./two/two.js":5}],3:[function(require,module,exports){ var 1 = "one"; },{}],4:[function(require,module,exports){ var 3 = "three"; },{}],5:[function(require,module,exports){ var 2 = "two"; },{}]},{},[2]) 

as can see, 'three' bundle before 'two' thats not order required them in?

looks it’s alphabetical. maybe browserify sorts them way or that’s how comes os. doesn’t make difference—those module definitions. code, inside (require, module, exports) functions, run same no matter order modules defined in.

here’s simplified version of browserify doing may more clear:

var modules = {   './app.js': function (require, module, exports) {     require('./one/one.js');     require('./two/two.js');     require('./three/three.js');   },   './two/two.js': function (require, module, exports) {     console.log('two');   },   './one/one.js': function (require, module, exports) {     console.log('one');   },   './three/three.js': function (require, module, exports) {     console.log('three');   } };  function require (path) {   var module = {exports: {}};   modules[path](require, module, module.exports);   return module.exports; }  require('./app.js'); 

even if change order modules defined should see same output:

one 2 3 

Comments

Popular posts from this blog

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -