title: How to bundle vendor scripts separately and require them as needed with Webpack?
body: <p>I'm trying to do something that I believe should be possible, but I really can't understand how to do it just from the webpack documentation.</p>
  
  <p>I am writing a JavaScript library with several modules that may or not depend on each other. On top of that, jQuery is used by all modules and some of them may need jQuery plugins. This library will then be used on several different websites which may require some or all modules.</p>
  
  <p>Defining the dependencies between my modules was very easy, but defining their third-party dependencies seems to be harder then I expected.</p>
  
  <p><strong>What I would like to achieve</strong>: for each app I want to have two bundle files one with the necessary third-party dependencies and other with the necessary modules from my library.</p>
  
  <p><strong>Example</strong>:
  Let's imagine that my library has the following modules:</p>
  
  <ul>
  <li>a (requires: jquery, jquery.plugin1)</li>
  <li>b (requires: jquery, a)</li>
  <li>c (requires: jquery, jquery.ui, a, b)</li>
  <li>d (requires: jquery, jquery.plugin2, a)</li>
  </ul>
  
  <p>And I have an app (see it as a unique entry file) that requires modules a, b and c. Webpack for this case should generate the following files:</p>
  
  <ul>
  <li><strong>vendor bundle</strong>: with jquery, jquery.plugin1 and jquery.ui;</li>
  <li><strong>website bundle</strong>: with modules a, b and c;</li>
  </ul>
  
  <p>In the end, I would prefer to have jQuery as a global so I don't need to require it on every single file (I could require it only on the main file, for example). And jQuery plugins would just extend the $ global in case they are required (it is not a problem if they are available to other modules that don't need them).</p>
  
  <p>Assuming this is possible, what would be an example of a webpack configuration file for this case? I tried several combinations of loaders, externals, and plugins on my configuration file, but I don't really get what they are doing and which ones should I use. Thank you!</p>