这个那问题很重要如何安全的安装webpack ,卸载webpack。主要是为了防止玩webpack玩坏了还可以从西再来,请老司机带个路,晚上回去可能要从做系统了😄
刚入门
看着文档全局安装webpack4.x,
npm install --global webpack
顺带也安装了webpack-cli
npm install --save-dev webpack-cli
检查版本
webpack -v
输出内容是 4.10.2
当时感觉非常nice
问题是我又考虑练手问题 直接
rm -rf node_modules package-lock.json
现在问题来了 我继续安装了webpack
lifedeMBP:Documents life$ webpack
-bash: /Users/life/.nvm/versions/node/v10.3.0/bin/webpack: No such file or directory
lifedeMBP:Documents life$ npm install --global webpack
/Users/life/.nvm/versions/node/v10.3.0/bin/webpack -> /Users/life/.nvm/versions/node/v10.3.0/lib/node_modules/webpack/bin/webpack.js
> fsevents@1.2.4 install /Users/life/.nvm/versions/node/v10.3.0/lib/node_modules/webpack/node_modules/fsevents
> node install
[fsevents] Success: "/Users/life/.nvm/versions/node/v10.3.0/lib/node_modules/webpack/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
+ webpack@4.11.0
added 387 packages from 296 contributors in 71.214s
lifedeMBP:Documents life$ webpack
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):
webpack-cli
Installing 'webpack-cli' (running 'npm install -D webpack-cli')...
npm WARN saveError ENOENT: no such file or directory, open '/Users/life/Documents/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/Users/life/Documents/package.json'
npm WARN webpack-cli@3.0.2 requires a peer of webpack@^4.x.x but none is installed. You must install peer dependencies yourself.
npm WARN Documents No description
npm WARN Documents No repository field.
npm WARN Documents No README data
npm WARN Documents No license field.
+ webpack-cli@3.0.2
added 105 packages from 44 contributors and audited 143 packages in 25.231s
found 0 vulnerabilities
{ Error: Cannot find module 'webpack-cli'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
at Function.Module._load (internal/modules/cjs/loader.js:520:25)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
at runCommand.then (/Users/life/.nvm/versions/node/v10.3.0/lib/node_modules/webpack/bin/webpack.js:149:5)
at process._tickCallback (internal/process/next_tick.js:68:7) code: 'MODULE_NOT_FOUND' }
lifedeMBP:Documents life$
开个玩笑(我在想我是不是要给mac从新做个系统)
删除全局webpack-cli
webpack4.x开始官方文档是说要安装cli所以如果的在用4.+就需要卸载cli
删除本地(局部)webpack-cli
删除全局webpack
删除本地webpack
检查webpack残余文件
安装webpack
接下来让我告诉你安装webpack4.+的正确方式
其实官方文档说的很清楚了,但是有点细节要注意。
创建一个新的本地项目目录名为webpack-demo
进入目录
创建package.json文件
安装webpack
安装webpack-cli
检查webpack是否安装成功
好了webpack的卸载和安装就到这了,喜欢我的可以点一个关注。我是一个喜欢编程的小白
千日醉兰