webpack4.0.1 installation problems and solutions

At the end of February, webpack4 was officially released, but when we installed it and used the following statement to package, we found that the packaging failed

webpack ./src/main.js ./dist/bundle.js

and gives the following hint:

1
2
3
4
5
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

It probably means: cli has been moved to a package called webpack-cli, please install webpack-cli to use cli in addition to webpack itself,

When using npm: npm install webpack-cli -D

When using yard:yarn add webpack-cli -D

And when we look at the webpack version number, the version number doesn't show up either

1
webpack -v

 Solution:

Install webpack-cli globally

1
npm install webpack-cli -g

After the installation is complete, the version number will be displayed.

Note: After installation, when packaging files, you must configure the entry and exit files in the webpack.config.js file to package, otherwise an error will be reported. When using it, try not to use it in the production environment. The official website also said a sentence : Be careful when installing these latest experience versions! They may still contain bugs and should not be used in production environments.

Install webpack-cli locally in the project directory -D

1
npm install webpack-cli -D

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325609056&siteId=291194637