Chris
Chris

Reputation: 613

How to manage external library dependencies for multiple entries in webpack?

In our projects, we have multiple webpack entries. They have dependencies for 3rd-party libraries (e.g. angularJS, fileAPI and so on). What we would like to achieve are:

Upvotes: 0

Views: 841

Answers (1)

Thaadikkaaran
Thaadikkaaran

Reputation: 5226

You can achieve your first two bullet points.

  1. Yes, external dependencies/libraries could be different entry point something like

    ...
    vendor: ["jquery", "underscore", ...],
    ...
    

    and add the CommonsChunkPlugin plugin to your plugin list.

    new webpack.optimize.CommonsChunkPlugin("vendor", "vendor.bundle.js")
    
  2. Ok, if you don't want to bundle them, and want to reference as a separate file, you can make separate entry point for each libs/dependencies or you can use script tags to load them separately.

    ...
    dep1: 'dep1',
    dep2: 'dep2',
    ...
    
  3. No, you can't achieve this point as webpack bundles whatever require-d with your own entry point and their reference files until unless you use code-splitting feature.

Upvotes: 1

Related Questions