Webpack

5.106.2 · active · verified Sat Apr 18

Webpack is a powerful and highly configurable module bundler that takes all your project's assets—JavaScript, CSS, images, fonts, and more—and packages them for deployment, primarily for the browser. It allows you to split your codebase into multiple chunks for optimized, asynchronous loading. The current stable version is 5.106.2, and it receives frequent patch and minor updates to enhance features and stability.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a basic webpack configuration to bundle a JavaScript file and an imported CSS file into `dist/bundle.js`. To run, save the config, create the `src` files, then execute `npm install --save-dev webpack webpack-cli style-loader css-loader` followed by `npx webpack`.

/* webpack.config.js */
const path = require('path');

module.exports = {
  mode: 'development', // 'production' or 'none'
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
  // Add basic loader for CSS as an example
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: ['style-loader', 'css-loader'],
      },
    ],
  },
};

/* src/index.js */
import './style.css';
console.log('Hello from Webpack!');

/* src/style.css */
body { font-family: sans-serif; }

view raw JSON →