Expose webpack bootstrap/runtime as a chunk

Do you want to request a feature or report a bug?
I would like to request a feature.

If this is a feature request, what is motivation or use case for changing the behavior?
There might be some use cases where, even if you’re using CommonChunksPlugin to move the runtime/bootstrap code in a common chunk, you might have some entries where you want the runtime to be embedded into (for usability purposes like one file-drop-in-page scripts).

Let me try to explain that with a practical example

I have 3 entries:

application: 'src/app.js'
seedFile: 'src/seed.js'
vendor: ['jquery', 'axios', 'otherLibs']

And then I’m using the CommonChunksPlugin for the vendor entry

new webpack.optimize.CommonsChunkPlugin
  name: 'vendor'
  minChunks: Infinity

The plugin will remove all the references to selected libraries and bundle them just once in the common chunk.

The webpack runtime/bootstrap code gets bundled into vendor.js file as well, which means I have to include two files in my application in order to make it work:

<script src="vendor.js"></script>
<script src="application.js"></script>

And that is totally ok.

Now what I would like to have is that the seed entry would be “self-contained”, which means I can use it without having to serve the vendor.js file in order to get the runtime/bootstrap code instantiated.

Note: the seed entry does NOT contain any dependency to any vendor library. The only reason to include that file is simply to have the web pack bootstrap/runtime code.

I have been looking (and asking) on both gitter and stack overflow, but it seems like this feature is not present in webpack.

I know that it’s possible to extract the runtime/manifest chunk using the CommonChunksPlugin with a non existing chunk as name – the problem is that the it’s not possible to use the extracted chunk in entries.

Thanks a lot, and keep going with the great work 👍

Author: Fantashit

1 thought on “Expose webpack bootstrap/runtime as a chunk

  1. You can use the chunks option of the CommonsChunkPlugin:

    new CommonsChunkPlugin({
      name: "vendor",
      chunks: ["application"],
      minChunks: Infinity

Comments are closed.