Webpack 安装使用(详细步骤)

简介: Webpack 安装使用(详细步骤)

$ 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/node_modules/webpack/node_modules/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}
  • 完成之后重新继续安装。

相关文章
|
6月前
|
缓存 JavaScript 前端开发
webpack超详细教程,学webpack看这一篇就够了!(下)
webpack超详细教程,学webpack看这一篇就够了!(下)
|
6月前
|
缓存 JSON 前端开发
webpack超详细教程,学webpack看这一篇就够了!(上)
webpack超详细教程,学webpack看这一篇就够了!(上)
|
JavaScript
Webpack 配置开发环境与正式环境
Webpack 配置开发环境与正式环境
87 0
|
6月前
|
安全 前端开发 中间件
webpack开发环境
webpack开发环境
55 0
|
前端开发
Webpack 安装教程
Webpack 安装教程
|
缓存 前端开发 JavaScript
学会用Webpack搭建开发环境并打包代码
学会用Webpack搭建开发环境并打包代码
135 0
学会用Webpack搭建开发环境并打包代码
|
JavaScript 中间件 开发工具
Webpack5 系列(三):开发环境的设置2
Webpack5 系列(三):开发环境的设置2
182 0
Webpack5 系列(三):开发环境的设置2
|
开发者
Webpack5 系列(三):开发环境的设置1
Webpack5 系列(三):开发环境的设置
74 0
|
人工智能 JavaScript
nodejs安装webpack详细步骤
nodejs安装webpack详细步骤