- Webpack官网、Node.js官网、npm官网、npm中文官网、npm使用以及命令含义
- Webpack 需要基于 Node.js、npm
- 如果是使用 Vue 进行开发,vue 自带的脚手架里面就包含了 Webpack,可以直接项目内使用。当然也可以自己在安装一个自己玩使用,毕竟那个是在脚手架里面的,外部还是可以在安装一个自己玩的。
- MAC电脑 Node.js 、npm 推荐使用 Homebrew 进行安装管理
$ brew install node $ brew install npm
- 安装完成之后,检查是否安装成功
dengzemiaodeMacBook-Pro:~ dengzemiao$ npm -v 6.13.0 dengzemiaodeMacBook-Pro:~ dengzemiao$ node -v v12.9.1
- 安装 Webapck、Webpack-cli
1、安装 webpack
// 安装 $ npm install webpack -g // 移除 $ npm uninstall webpack -g ``` dengzemiaodeMacBook-Pro:~ dengzemiao$ npm install webpack -g npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2. /usr/local/bin/webpack -> /usr/local/lib/node_modules/webpack/bin/webpack.js
fsevents@1.2.13 install /usr/local/lib/nodemodules/webpack/nodemodules/watchpack-chokidar2/node_modules/fsevents node install.js
SOLINK_MODULE(target) Release/.node CXX(target) Release/obj.target/fse/fsevents.o SOLINK_MODULE(target) Release/fse.node
npm WARN notsup Unsupported engine for watchpack-chokidar2@2.0.0: wanted: {"node":"<8.10.0"} (current: {"node":"12.9.1","npm":"6.13.0"}) npm WARN notsup Not compatible with your version of node/npm: watchpack-chokidar2@2.0.0
- webpack@4.43.0 added 347 packages from 210 contributors and updated 1 package in 38.597s ```
2、安装 webpack-cli,webpack 现在新版本需要依赖于这个脚手架。
// 安装 $ npm install webpack-cli -g // 移除 $ npm uninstall webpack-cli -g ``` dengzemiaodeMacBook-Pro:~ dengzemiao$ npm install webpack-cli -g /usr/local/bin/webpack-cli -> /usr/local/lib/node_modules/webpack-cli/bin/cli.js npm WARN webpack-cli@3.3.12 requires a peer of webpack@4.x.x but none is installed. You must install peer dependencies yourself.
- webpack-cli@3.3.12 added 185 packages from 127 contributors in 20.243s ```
3、检查是否安装
// 查看帮助 $ webpack -h // 查看版本 $ webpack -v dengzemiaodeMacBook-Pro:~ dengzemiao$ webpack -v 4.43.0
到这里就安装成功了!!
- 如果安装中出现这种文件权限错误
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/webpack/bin/webpack.js' -> '/usr/local/bin/webpack'' npm ERR! Please try running this command again as root/Administrator
- 可以通过打开权限进行,该操作需要输入密码
$ sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
- 完成之后重新继续安装。