javascript - How to manage dependencies with browserify when not using components? -


i using gulp browserify pull js dependencies 1 file, minify file production. problem order in requiring modules not order in output.

as simplified example, have script.js file goes:

var $         = require('jquery'); var gsap      = require('gsap'); var hi        = require('hoverintent');   $('#someid').hoverintent(function(){     //do },function(){     //do } 

but error "hoverintent not function".

i @ output file , see browserify writing hoverintent plugin before jquery dependency though require jquery first.

is normal behavior"? if best practice dependency management sort of case? limited experience browserify in past has been reactjs, , in case required dependencies each component worked fine. best practice site / app not use components?

your problem relying on side effect of hoverintent plugin adding it's function jquery. why jquery plugins/extensions smell let's ignore that.

you should have 1 module requires jquery, adds hoverintent function jquery , exports jquery has function on it. should use module instead of requiring jquery directly.

the normal commonjs pattern is:

  1. have behavior - wrap in module.
  2. when need behavior, require module , use with variable name required to.

note how #2 being violated in code above -- require hoverintent hi not use such. putting issue down in custom jquery (which jquery plus hoverintent), push annoying pattern violation off 1 module instead of repeat across code base.

you can of course augment jquery when plugin. other reply includes example , i'll put right here:

var $ = require('jquery'); require('hoverintent-jqplugin')($); 

my viewpoint mutated jquery , best put mutation in 1 place. why suggest pushing down 1 module. mutate, mean when module requires jquery after module, have .hoverintent if requiring jquery before, won't. if rest of team doesn't understand 100%, things can messy (and if understand it, still messy).


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -