Webpack Bootstrapping: Three Commands, Five Concepts, One Bundle
Webpack configuration trips up developers at the loader-order and package-name level; this note condenses the setup into three commands and five concepts, so a developer who needs a working build can get it running and know what each piece does.
A practical note walks through setting up a webpack build from an empty directory. Three commands get the project running: initialize with `npm init -y`, install webpack, the CLI, loaders, and plugins, then run `npx webpack`. A script entry in `package.json` swaps the direct call for `npm run build` and adds a watch mode with `npm run dev`. The project structure places source files in `src/` and configuration in `webpack.config.js` and `.babelrc`.
Five core concepts frame the configuration: entry, output, loader, plugin, and mode. Loaders translate non-JS files into modules webpack understands; plugins extend functionality at build lifecycle hooks. The bundling flow starts at the entry, follows `import` statements recursively, applies loaders, and merges everything into a single bundle. An example config shows `babel-loader` for JavaScript and `style-loader` plus `css-loader` for CSS, with the `use` array executing right to left.
The output lands in `dist/` as `bundle.js` and an auto-injected `index.html`. Development mode leaves the bundle unminified at about 24KB; production mode compresses it to a few kilobytes. The guide closes with a memory rhyme that reduces the workflow to `npm install` for dependencies and `npx webpack` for bundling, everything else being configuration.