Search code examples
javascriptjquerygruntjsbrowserifyshim

Shim a jQuery plugin with browserify


Hi I'm using the grunt browserify task to setup my code, I have shimmed in jQuery and I'm now trying to include jquery.tablesorter.

Can jquery plugins be used with browserify in this way?

shim: {
    jquery: {
        path: 'lib/bower/jquery/jquery.js',
        exports: '$'
    },
    'jquery.tablesorter': {
        path: 'lib/bower/jquery.tablesorter/js/jquery.tablesorter.js',
        exports: 'tablesorter',
        depends: {
            jquery: '$',
        }
    }
}

Solution

  • You may try by doing this:

    shim: {
        jquery: {
            path: 'lib/bower/jquery/jquery.js',
            exports: '$'
        },
        'jquery.tablesorter': {
            path: 'lib/bower/jquery.tablesorter/js/jquery.tablesorter.js',
            exports: null,
            depends: {
                jquery: '$',
            }
        }
    }
    

    If the above is not working, you can try this:

    shim: {
        jquery: {
            path: 'lib/bower/jquery/jquery.js',
            exports: null
        },
        'jquery.tablesorter': {
            path: 'lib/bower/jquery.tablesorter/js/jquery.tablesorter.js',
            exports: null,
            depends: {
                jquery: 'jQuery',
            }
        }
    }