Author avatar

Solomon Ayoola

How to Use One Vendor Chunk File (Webpack) for Multiple React Projects

Solomon Ayoola

  • Apr 2, 2020
  • 5 Min read
  • Apr 2, 2020
  • 5 Min read
Web Development
Front End Web Development
Client-side Framework


In many projects that use React, starting up might take 20–30 seconds. That is a pretty large window to get distracted and do something else.

In this guide, we will be talking about how to use one vendor chunk file for multiple react projects using DLL. This article assumes some level of familiarity with Webpack and React. Here is a link to get you started.

What is DLL?

DLL (Dynamic-Link Library), originally introduced by Microsoft, is a library that contains code and data that can be used by more than one program at the same time.

The following are some of the benefits of using DLL:

  • Increased incremental build speed
  • Promotes code reuse
  • Efficient memory usage

Webpack provides plugins such as DllPlugin and DllReferencePlugin that allow you to extract the libraries that rarely change and reference them in our project instead of building them every time.

The following steps will walk you through how to use DLL with webpack.


Create the DLL bundle

To get started, create a file called vendor.js that points to all commonly used libraries in a project:


Build the DLL Libraries

To build the DLL libraries, create a new webpack.config.dll.js file with the following configuration:

1const webpack = require("webpack");
2const path = require("path");
4module.exports = {
5  context: __dirname,
6  entry: {
7    vendor: [path.join(__dirname, "vendor.js")]
8  },
9  devtool: "#source-map",
10  mode: "development",
11  output: {
12    path: path.join(__dirname, "build"),
13    filename: "[name].js",
14    library: "[name]"
15  },
16  plugins: [
17    new webpack.DllPlugin({
18      path: path.join(__dirname, "vendor", "[name]-manifest.json"),
19      name: "[name]"
20    })
21  ]

The configuration above looks fairly straight forward except the DllPlugin, which is used in a separate webpack configuration exclusively to create a dll-only-bundle.

DllPlugin creates a manifest.json file, which is then used by DllReferencePlugin to map dependencies.

Running the following command:

1webpack --config webpack.config.dll.js

creates creates two files, which are going to be used in the next steps

  • build/vendor.js
  • vendor/vendor-manifest.json

Build the project

After creating the DLL bundle, you'll need to reference it in the webpack.config.js using DllReferencePlugin as shown below:

1const path = require('path');
2const webpack = require('webpack')
4module.exports = {
5  // other config...
6  plugins: [
7    new webpack.DllReferencePlugin({
8      context: __dirname,
9      manifest: require("./vendor/vendor-manifest.json")
10    }),
11  ]

The DllReferencePlugin loads the libraries in the manifest file from DllPlugin and references them in the source code.

This also works if you have multiple projects. You just need to reference the generated manifest.json file in the webapck.config.js of the respective projects

Vendor file in HTML

You can manually add vendor/vendor.js to the HTML file, but this does not work well with dynamical filenames.

To combat guessing of filenames and other assets that need to be included in the HTML file, you can employ webpack plugins such as html-webpack-plugin and add-asset-html-webpack-plugin.

An updated webpack.config.js will look like this:

1const path = require("path");
2const webpack = require("webpack");
3const HtmlWebpackPlugin = require("html-webpack-plugin");
4const AddAssetHtmlPlugin = require("add-asset-html-webpack-plugin");
6module.exports = {
7  context: __dirname,
8  entry: path.join(__dirname, "app.js"),
9  devtool: "#source-map",
10  mode: "development",
11  output: {
12    path: path.join(__dirname, "build"),
13    filename: "[name].js",
14    chunkFilename: "[name].js"
15  },
16  plugins: [
17    new webpack.DllReferencePlugin({
18      context: __dirname,
19      manifest: require("./vendor/vendor-manifest.json")
20    }),
21    new HtmlWebpackPlugin(),
22    new AddAssetHtmlPlugin({
23      filepath: path.resolve(__dirname, "./build/vendor.js")
24    })
25  ]

While the DllPlugin has many advantages, its main drawback is that it requires a lot of boilerplate. You can check out autodll-webpack-plugin, which serves as a high-level plugin for both the DllPlugin and the DllReferencePlugin, and hides away most of their complexity.


This guide has provided a walkthrough of how you can reuse one vendor chunk file in multiple React projects.

Here are some useful links: