Skip to main content
Webpack CLI provides numerous flags to customize the build process, output, optimization, and more.

Entry and Output

--entry
string
Entry point(s) for the bundle.
webpack --entry ./src/index.js
webpack --entry ./src/app.js --entry ./src/vendor.js
--output-path
path
Output directory for all build files.
webpack --output-path ./dist
--output-filename
string
Filename template for entry chunks.
webpack --output-filename [name].[contenthash].js
--output-public-path
string
Public URL of the output directory when referenced in a browser.
webpack --output-public-path /assets/
--output-clean
boolean
Clean the output directory before emit. Default: false
webpack --output-clean

Mode and Environment

--mode
enum
Build mode. Sets defaults and process.env.NODE_ENV.Values: development | production | none
webpack --mode production
--env
object
Environment variables passed to config function.
webpack --env production
webpack --env.production --env.platform=web
--node-env
string
Sets process.env.NODE_ENV to the specified value.
webpack --node-env production

Configuration

--config
path
Path to webpack configuration file.
webpack --config webpack.prod.js
webpack --config config/webpack.config.js
--config-name
string
Name of the configuration to use (for multi-config exports).
webpack --config-name production
--merge
boolean
Merge two or more configurations.
webpack --config webpack.base.js --config webpack.prod.js --merge

Development

--watch
boolean
Watch files for changes and rebuild. Default: false
webpack --watch
--watch-options-stdin
boolean
Stop watching when stdin stream ends.
webpack --watch --watch-options-stdin
--devtool
string
Source map generation method.
webpack --devtool source-map
webpack --devtool eval-source-map
--hot
boolean
Enable Hot Module Replacement. Default: false
webpack serve --hot

Optimization

--optimization-minimize
boolean
Minimize the output. Default: true in production mode.
webpack --optimization-minimize
webpack --no-optimization-minimize
--optimization-concatenate-modules
boolean
Enable module concatenation (scope hoisting).
webpack --optimization-concatenate-modules
--optimization-runtime-chunk
boolean | string
Create a separate chunk for the webpack runtime.
webpack --optimization-runtime-chunk single
--optimization-split-chunks
boolean
Enable/disable code splitting.
webpack --optimization-split-chunks

Module Resolution

--resolve-alias
object
Create aliases for module imports.
webpack --resolve-alias @=./src
--resolve-extensions
array
Extensions to resolve.
webpack --resolve-extensions .js --resolve-extensions .jsx
--resolve-modules
array
Directories to search for modules.
webpack --resolve-modules node_modules --resolve-modules src

Performance

--performance-hints
enum
Show performance hints.Values: warning | error | false
webpack --performance-hints warning
--performance-max-entrypoint-size
number
Max size (in bytes) for entrypoint assets.
webpack --performance-max-entrypoint-size 250000
--performance-max-asset-size
number
Max size (in bytes) for individual assets.
webpack --performance-max-asset-size 250000

Stats and Output

--stats
string | boolean
Stats output preset.Presets: none | errors-only | errors-warnings | minimal | normal | verbose | detailed
webpack --stats verbose
webpack --stats detailed
--stats-error-details
boolean
Show details for errors.
webpack --stats-error-details
--progress
boolean
Show compilation progress percentage.
webpack --progress
--json
boolean | string
Output stats as JSON. Optionally specify output file path.
webpack --json
webpack --json=stats.json
--color
boolean
Enable/disable colors in console output.
webpack --color
webpack --no-color

Target and Platform

--target
string | array
Build target environment.Common values: web | node | async-node | electron-main | electron-renderer
webpack --target node
webpack --target web --target es2020

Cache

--cache
boolean
Enable/disable caching.
webpack --cache
webpack --no-cache
--cache-type
enum
Cache type.Values: memory | filesystem
webpack --cache-type filesystem

Analyze and Debug

--analyze
boolean
Generate bundle analysis.
webpack --analyze
--profile
boolean
Capture timing information for each module.
webpack --profile
--bail
boolean
Abort compilation on first error.
webpack --bail

DevServer Options

These flags are available when using webpack serve:
--port
number
Port number for dev server. Default: 8080
webpack serve --port 3000
--host
string
Host to use. Default: localhost
webpack serve --host 0.0.0.0
--open
boolean | string
Open browser. Optionally specify browser name or page path.
webpack serve --open
webpack serve --open chrome
webpack serve --open /about
--static
string | array
Directory to serve static files from.
webpack serve --static ./public
--compress
boolean
Enable gzip compression.
webpack serve --compress
--https
boolean
Enable HTTPS.
webpack serve --https
--http2
boolean
Enable HTTP/2.
webpack serve --http2

Utility Flags

--help
boolean
Display help information.
webpack --help
webpack build --help
--version
boolean
Display webpack version.
webpack --version
--silent
boolean
Prevent output from being displayed in stdout.
webpack --silent

Negating Boolean Flags

Boolean flags can be negated by prefixing with no-:
# Disable optimization
webpack --no-optimization-minimize

# Disable colors
webpack --no-color

# Disable cache
webpack --no-cache

Flag Priority

When the same option is specified multiple times, the last value takes precedence:
# Uses production mode
webpack --mode development --mode production
CLI flags override configuration file settings:
# CLI flag overrides config
webpack --config webpack.config.js --mode production

See Also