Copy duplicate library code

I want to put all vendor files (like jQuery, moment.js, bootstrap.js, etc.) in vendors.js file and export jQuery from there to reuse it in other modules.

due to bootstrap depends on jQuery, I fit both modules and set up 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"

      

<strong> shim-config.js

'use strict';

module.exports = {
  'jquery'    :  'jQuery',
  'bootstrap' :  { 'depends': { 'jquery': 'jQuery'} }
};

      

to reuse jQuery as an external dependency. I specified it in the method call require

when creating 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 the jQuery code was included twice in vendors.js: once to resolve dependencies and once to export the library. Given the size of jQuery, this is a significant problem.

Can anyone help me solve it?

+3


source to share





All Articles