webpack build
Compiles your webpack project.Syntax
Description
Thebuild command compiles your webpack configuration and outputs bundled assets. This is the default command when running webpack without any subcommand.
Usage Examples
Return Value
Exits with code0 on success, non-zero on error.
webpack serve
Starts a development server with live reloading.Syntax
Description
Theserve command starts webpack DevServer, which provides live reloading and hot module replacement for development.
Requires
webpack-dev-server to be installed.Usage Examples
Parameters
Port number for the dev server. Default:
8080Host to use for the dev server. Default:
localhostEnable hot module replacement. Default:
trueOpen the browser after server starts. Default:
falsewebpack watch
Watches files and rebuilds on changes.Syntax
Description
Thewatch command starts webpack in watch mode. It monitors your source files and automatically rebuilds when changes are detected.
Usage Examples
Parameters
Stop watching when stdin stream ends. Default:
falsePolling interval in milliseconds. Use when file watching doesn’t work.
Return Value
Runs continuously until terminated. Exits with code0 on graceful shutdown.
webpack init
Scaffolds a new webpack project.Syntax
Description
Theinit command helps you create a new webpack configuration interactively. It can use built-in templates or custom scaffolds.
Requires
@webpack-cli/generators to be installed.Usage Examples
Parameters
Name of the scaffold template to use. If omitted, uses interactive mode.
Overwrite existing files without prompting. Default:
falseTemplate to generate from. Can be a package name or local path.
Return Value
Exits with code0 on successful initialization, non-zero on error.
Common Options
These options work with all commands:Path to webpack configuration file. Default:
webpack.config.jsBuild mode:
development, production, or none. Sets process.env.NODE_ENV and applies defaults.Environment variables passed to the config function.
Stats output preset:
none, errors-only, minimal, normal, verbose, detailed.Show compilation progress. Default:
falseDisplay help information.
Display webpack version.
Exit Codes
| Code | Description |
|---|---|
0 | Success |
1 | Errors from webpack |
2 | Configuration or options error |
See Also
- CLI Flags - Complete list of CLI flags and options
- Configuration - webpack configuration reference
- DevServer - Development server options