Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tab-completions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"webpack-cli": minor
---

feat: add shell completions for zsh, bash, fish and powershell through the `complete` command
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
"Zenitsu",
"quickstart",
"pinia",
"watchpack"
"watchpack",
"zsh"
],
"dictionaries": ["npm", "software-terms"],
"ignorePaths": [
Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- [Packages](#packages)
- [Commands](#commands)
- [Getting started](#getting-started)
- [Shell completion](#shell-completion)
- [Exit codes and their meanings](#exit-codes-and-their-meanings)
- [Contributing and Internal Documentation](#contributing-and-internal-documentation)
- [Funding](#funding)
Expand Down Expand Up @@ -58,6 +59,7 @@ Supporting developers is an important task for webpack CLI.
Thus, webpack CLI provides different commands for many common tasks.

- [`build|bundle|b [entries...] [options]`](https://webpack.js.org/api/cli/#build) - Run webpack (default command, can be omitted).
- `complete [shell]` - Print a shell completion script, see [Shell completion](#shell-completion).
- [`configtest|t [config-path]`](https://webpack.js.org/api/cli/#configtest) - Validate a webpack configuration.
- [`help|h [command] [option]`](https://webpack.js.org/api/cli/#help) - Display help for commands and options.
- [`info|i [options]`](https://webpack.js.org/api/cli/#info) - Returns information related to the local environment.
Expand All @@ -79,6 +81,41 @@ npx create-webpack-app init

You will then be prompted for some questions about which features you want to use, such as `scss`, `typescript`, `PWA` support or other features.

## Shell completion

Commands, their options and the values those options accept can be completed in `zsh`, `bash`, `fish` and `powershell`. The completions are read from webpack's own schema, so they cover whatever your webpack and `webpack-dev-server` versions support.

Completion is served by [`@bomb.sh/tab`](https://www.npmjs.com/package/@bomb.sh/tab), which is optional and not installed with `webpack-cli`:

```sh
npm install --save-dev @bomb.sh/tab
```

Then load the script for your shell:

```sh
# zsh
echo 'source <(webpack complete zsh)' >> ~/.zshrc

# bash
echo 'source <(webpack complete bash)' >> ~/.bashrc

# fish
webpack complete fish > ~/.config/fish/completions/webpack.fish

# powershell
webpack complete powershell > ~/.webpack-completion.ps1
echo '. ~/.webpack-completion.ps1' >> $PROFILE
```

Once the shell is restarted, `Tab` completes commands, their aliases, options and option values:

```sh
webpack b<Tab> # webpack build
webpack build --mode=<Tab> # development, production, none
webpack serve --his<Tab> # webpack serve --history-api-fallback
```

## Exit codes and their meanings

| Exit Code | Description |
Expand Down
35 changes: 33 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"prepare": "husky"
},
"devDependencies": {
"@bomb.sh/tab": "^0.0.22",
"@babel/core": "^8.0.1",
"@babel/preset-env": "^8.0.2",
"@babel/register": "^8.0.1",
Expand Down
1 change: 1 addition & 0 deletions packages/webpack-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ npx webpack-cli --help verbose

```
build|bundle|b [entries...] [options] Run webpack (default command, can be omitted).
complete [shell] Generate shell completion scripts.
configtest|t [config-path] Validate a webpack configuration.
help|h [command] [option] Display help for commands and options.
info|i [options] Outputs information about your system.
Expand Down
4 changes: 4 additions & 0 deletions packages/webpack-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@types/envinfo": "^7.8.4"
},
"peerDependencies": {
"@bomb.sh/tab": "^0.0.22",
"js-yaml": "^4.0.0 || ^5.0.0",
"json5": "^2.2.3",
"toml": "^3.0.0 || ^4.0.0 || ^5.0.0",
Expand All @@ -52,6 +53,9 @@
"webpack-dev-server": "^5.0.0 || ^6.0.0"
},
"peerDependenciesMeta": {
"@bomb.sh/tab": {
"optional": true
},
"js-yaml": {
"optional": true
},
Expand Down
Loading
Loading