Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can webpack bundle different versions of the same dependency

Tags:

I've a project made of different widgets that all share the same vendor. I would like to know if I could bundle different versions of the same vendor library:

widget A

  • lib 1.0.0

widget B

  • lib 2.0.0

bundle

  • widgetA.js
  • widgetB.js
  • vendor.js (lib 1.0.0 + lib 2.0.0)
like image 342
a--m Avatar asked Mar 16 '18 14:03

a--m


People also ask

How does webpack bundling work?

When webpack processes your application, it internally builds a dependency graph from one or more entry points and then combines every module your project needs into one or more bundles, which are static assets to serve your content from.

Are packages and dependencies the same?

A dependency is a code that your package needs to run. Dependencies are managed by two files. The DESCRIPTION manages dependencies at the package level; i.e. what packages needs to be installed for your package to work.

Is webpack for dependency management?

Webpack is a build tool to manage your dependencies (css, js, etc.).

Does webpack bundle node_modules?

Webpack allows you to define externals - modules that should not be bundled. When bundling with Webpack for the backend - you usually don't want to bundle its node_modules dependencies. This library creates an externals function that ignores node_modules when bundling in Webpack.


1 Answers

So I found that NPM provides a way to alias the names of modules/libraries upon installation. I tested this and it works great, and the 2 versions of jQuery are even bundled in the same vendors.bundle by Webpack. Here's the module alias syntax:

npm install jquery2@npm:jquery@2
npm install jquery3@npm:jquery@3
like image 179
Ted Fitzpatrick Avatar answered Sep 20 '22 13:09

Ted Fitzpatrick