webpack4.0使用时提示npm install webpa
2018-03-05 本文已影响3277人
Jerry379
最近在看关于vue的书,在使用webpack构建项目时,遇到如下问题:
> webstormproject@1.0.0 dev /Users/********/WebstormProjects/webstormProject
> webpack-dev-server --open --config webpack.config.js
The CLI moved into a separate package: webpack-cli.
Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
-> When using yarn: yarn add webpack-cli -D
module.js:538
throw err;
^
Error: Cannot find module 'webpack-cli/bin/config-yargs'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/********/WebstormProjects/webstormProject/node_modules/webpack-dev-server/bin/webpack-dev-server.js:65:1)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
按照提示安装webpack-cli以后再次运行,运行成功。
有些安装以后仍然运行不成功的,可以在webpack.config.js中添加一项mode:'development',再次运行。
webpack4中添加了一个mode参数,这个参数有两个值: 'development'或者 'production',一个是开发环境,一个是生产环境。