One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:
- webpack-cli (https://github.com/webpack/webpack-cli)
The original webpack full-featured CLI.
- webpack-command (https://github.com/webpack-contrib/webpack-command)
A lightweight, opinionated webpack CLI.
We will use "npm" to install the CLI via "npm install -D".
Which one do you like to install (webpack-cli/webpack-command):
One CLI needs to be installed alongside webpack to use the CLI.
评论里的方法都试了还是不行
# 安装指定版本 npm install webpack@2.7.0 --g npm install webpack@2.7.0 --save-dev
出现这样的情况 大部分是因为版本的问题,可能教师讲的时候是3.x版本,而你装的版本是4.x 就会出现打包不成功的情况,可以在命令行 npm i webpack3.x -D 重新安装webpack 试试。
npm install webpack-cli -g
我也是用 npm 安装不成功。可以试试用淘宝的npm
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install webpack webpack-cli --save-dev
因为在webpack 3中,webpack本身和它的CLI以前都是在同一个包中,但在第4版中,他们已经将两者分开来更好地管理它们 所以你要执行一下 npm install webpack-cli --save-dev 命令。
npm i webpack-cli --save-dev