LinuxCommandLibrary

webpack

Static module bundler for JavaScript

TLDR

Build the project using default configuration
$ webpack
copy
Build with a specific configuration file
$ webpack --config [webpack.config.js]
copy
Build for production
$ webpack --mode production
copy
Build for development
$ webpack --mode development
copy
Watch for changes and rebuild
$ webpack --watch
copy
Specify output directory
$ webpack --output-path [path/to/dist]
copy
Start the development server
$ webpack serve
copy
Show build statistics
$ webpack --stats verbose
copy

SYNOPSIS

webpack [command] [entries...] [options]

DESCRIPTION

webpack is a static module bundler for modern JavaScript applications. It builds a dependency graph from entry points and bundles modules into optimized output files for browsers.
The CLI is provided by webpack-cli and wraps webpack's configuration options. Most options can be specified via command line or in webpack.config.js. CLI options override configuration file settings.
webpack supports code splitting, lazy loading, tree shaking, and various loaders and plugins for processing different file types (CSS, images, TypeScript, etc.).

PARAMETERS

build, bundle, b

Run webpack to bundle the project (default command).
serve, server, s
Run webpack dev server.
watch, w
Run webpack and watch for file changes.
init, create, c
Initialize a new webpack project.
info, i
Output information about your system.
configtest, t
Validate a webpack configuration file.
-c, --config file
Path to webpack configuration file.
--config-name name
Name of the configuration to use.
-m, --merge
Merge multiple configurations.
--mode mode
Set mode: production, development, or none.
-o, --output-path path
Output directory (absolute path).
-w, --watch
Watch mode, rebuild on file change.
--env value
Environment variables passed to config function.
--stats preset
Stats output level: errors-only, minimal, normal, verbose.
-v, --version
Display version information.
-h, --help
Display help message.

CAVEATS

webpack-cli must be installed separately from webpack core (npm install webpack webpack-cli). The dev server (webpack serve) requires webpack-dev-server. Complex configurations are better maintained in config files rather than CLI arguments.

HISTORY

webpack was created by Tobias Koppers and first released in March 2012. It revolutionized JavaScript build tooling by introducing concepts like code splitting and hot module replacement. webpack 4 (2018) focused on zero-config defaults, and webpack 5 (2020) improved build performance and module federation. The CLI was separated into webpack-cli starting with webpack 4.

SEE ALSO

npm(1), vite(1), rollup(1), esbuild(1), parcel(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard