Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use browserify-shim without package.json?

I need to use browserify-shim for some of my browserify dependencies, but I can't edit my package.json. I'm using browserify inside of gulp. It is possible to specify all of the package.json portion exclusibely form the API? I'm envisioning something like this:

return gulp.src('glob/path/to/my/main/js/file.js')
    .pipe(browserify({
        debug: false,
        transform: ['browserify-shim'],
        shim: {
            'jquery': {
                exports: 'jQuery'
            }
        }
    }));

Then, my output with repalce var $ = require('jquery'); with var $ = jQuery;, since we are now utilizing jQuery as a global. Is this possible? Whne

like image 254
AlexZ Avatar asked Dec 07 '25 21:12

AlexZ


1 Answers

You could use exposify transform in that case. browserify-shim is actially based on it and is written by the same guy.

E.g.:

return browserify('glob/path/to/my/main/js/file.js', { debug: false })
    .transform('exposify', { expose: {'jquery': 'jQuery' }})
like image 106
Kolya Ay Avatar answered Dec 10 '25 11:12

Kolya Ay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!