Webpack

Compile javascript into bundles more efficiently managing dependencies(don't expect some library to already be included)

Out of the box handles js and json, use loadersarrow-up-right to add more file types(css, imgs)

Use esbuild-loader for way faster building times

npm install webpack --save-dev
npm install webpack-cli --save-dev

webpack.config.js

const path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'main.js',
    path: path.resolve(__dirname, 'dist')
  }
};

Add Images

npm install file-loader url-loader
	module: {
	  rules: [
	  //....
      {
        test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
        loader: require.resolve("url-loader"),
        options: {
          limit: imageInlineSizeLimit,
          name: "../priv/static/media/[name].[hash:8].[ext]",
        },
      },
    ],
  },

Examples

A production web pack file

Visualizing

Create a viz of the libs increasing size of your bundle

Last updated