Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the point of webpack "runtime" files

Tags:

webpack

I am using webpack today for transpiling just my core business logic code, but are still using a CDN for all external libraries like jQuery, AngularJS, etc. I want to move these vendor libraries into webpack by using the SplitChunksPlugin, but when I followed an example I found here at SO I got the vendor bundle to get created, but at the same time it also created some extra files I am not sure about.

For every entry module I have declared in the webpack config, webpack not also creates a "runtime" version of these files"

For example I have a company.productA.core.bundle.js taht I have been using for a while but after adding the config for the split chunks I now also get a company.runtime~productA.core.bundle.js. Webpack has done the same for the other 8 modules I have being created.

I have tried searching for what these are but don't see anything about them on both the webpack documentation and SO.

Can someone explain to me what these files are meant for?

like image 717
Matt Hintzke Avatar asked Aug 31 '18 17:08

Matt Hintzke


People also ask

What is the webpack runtime?

Runtime. The runtime, along with the manifest data, is all the code webpack needs to connect your modularized application while it's running in the browser. It contains the loading and resolving logic needed to connect your modules as they interact.

Why do we need Webpacks?

This is why webpack exists. It's a tool that lets you bundle your JavaScript applications (supporting both ESM and CommonJS), and it can be extended to support many different assets such as images, fonts and stylesheets.

What does webpack do exactly?

Webpack is an aggressive and powerful module bundler for JavaScript applications. It packages all the modules in your application into one or more bundles (often, just one) and serves it to the browser.

Why do we need webpack loader?

Webpack enables use of loaders to preprocess files. This allows you to bundle any static resource way beyond JavaScript. You can easily write your own loaders using Node. js.


1 Answers

Each of the runtime files contains code that enables loading of your chunks. If you open any of those runtime files, you will see code that loads your chunks via Jsonp. Since you have asked webpack to split chunks, you are now free to load any chunk any time. Hence for each chunk, webpack emits these runtime files so that it can handle requires correctly.

like image 174
Ravi Tiwari Avatar answered Sep 28 '22 00:09

Ravi Tiwari