I want to place all vendors libraries (like jQuery, moment.js, bootstrap.js and so on) code into vendors.js file and export jQuery from it to reuse it in other modules.
because of bootstrap is dependent from jQuery, I shimed both modules and configure dependencies:
package.json
"browser": {
"bootstrap": "./node_modules/bootstrap/dist/js/bootstrap.js",
"jquery": "./node_modules/jquery/dist/jquery.js"
},
"browserify": {
"transform": [
"browserify-shim"
]
},
"browserify-shim": "gulp/utilities/shim-config.js"
shim-config.js
'use strict';
module.exports = {
'jquery' : 'jQuery',
'bootstrap' : { 'depends': { 'jquery': 'jQuery'} }
};
to reuse jQuery as external dependency I specified it in require
method call, when build my vendors.js
build
.require('jQuery')
.bundle()
.pipe(source('vendors.js'))
.pipe(gulp.dest('build/public/js'))
.pipe(plumber({
errorHandler: helpers.logError
}));
after building vendors.js I found, that jQuery code was included into vendors.js twice: one time to resolve dependency and one more time to export library. Considering size of jQuery it is significant issue.
Can anyone pls help me to solve it?