node.jsbrowserifyjquery.panzoom

How to implement jQuery.panzoom with node & browserify


On the plugin's github page there is the following explanation to implement the plugin via AMD loader:

define([ "jquery", "plugins/jquery.panzoom" ], function( $ ) {
  $(document).ready(function() {
    $(".panzoom-elements").panzoom();
  });
});

But how do I implement this plugin via nodejs & browserify?


Solution

  • This plugin uses UMD (Universal Module Definition) pattern, meaning you could use it also with CommonJS/Browserify module system as usual like any other lib/package.

    (See: these lines of source code).

    Installation:

    npm install jquery.panzoom --save
    

    Usage:

    main.js

    var $ = require('jquery');
    require('jquery.panzoom');
    
    $(document).ready(function() {
      $(".panzoom-elements").panzoom();
    });
    

    Browserify:

    browserify main.js -o bundle.js