Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see which files are included in a webpack build

Is there a way to see which files are included in a webpack build and preferably, their size? The reason I want this is to gain insight into my builds and also keep an eye out for accidental inclusion of files that should not be in there.

like image 216
Dennis Avatar asked Oct 19 '15 15:10

Dennis


People also ask

Where are webpack files?

Webpack will generate the files and put them in the /dist folder for you, but it doesn't keep track of which files are actually in use by your project. In general it's good practice to clean the /dist folder before each build, so that only used files will be generated.

What is webpack built with?

Webpack is a free and open-source module bundler for JavaScript. It is made primarily for JavaScript, but it can transform front-end assets such as HTML, CSS, and images if the corresponding loaders are included. Webpack takes modules with dependencies and generates static assets representing those modules.

What are webpack files?

Webpack is first and foremost a bundler. Webpack's base functionality is to take a JavaScript file, resolve any dependencies ( require() , import , etc.), and output a bundled JavaScript file that contains all those dependencies. You can then run the bundled file without having to load those dependencies again.


1 Answers

By default, the webpack CLI will print the path of all included modules and their respective size.

Webpack can also generate a stats.json file for you, which contains information about every module included in your build.

From the CLI:

webpack --json > stats.json

From the NodeJS API:

webpack(config, function(err, stats) {
  fs.writeFileSync('./stats.json', JSON.stringify(stats.toJson()));
});

You can then either write your own stats analyser tool, or use already existing tools like the excellent webpack stats analyser.

like image 121
Alexandre Kirszenberg Avatar answered Sep 27 '22 20:09

Alexandre Kirszenberg