webpack-dev-server是什么

陆昊
2023-12-01

最近接触一个项目,前后分离的,在启动前端的时候用到一个命令:npm run server ,感觉很神奇,直接可以让我们在浏览器中就可以访问网页或js了,很新奇,自己研究了一下,别忘记了。

首先说这是什么工具才用到的命令,网上各种搜,总结一下:

1.webpack-dev-server是一个小型的Node.js Express服务器,注意知识点:“服务器。

2.通过在package.json中配置可以通过npm命令启动,举个例子:package.json 的内容

{
  "name": "ibp_static",
  "version": "0.0.1",
  "description": "ibp_static",
  "scripts": {
    "server": "webpack-dev-server --hot --inline --config webpack.server.js",
    "dev": "webpack-dev-server --config webpack.dev.js",
    "build": "webpack -p --config webpack.dev.js"
  },
  "devDependencies": {
    "webpack": "3.5.5",
    "webpack-dev-server": "2.7.1",
    "extract-text-webpack-plugin": "3.0.0",
    "copy-webpack-plugin": "4.0.1",
    "clean-webpack-plugin": "0.1.16",
    "css-loader": "0.28.7",
    "file-loader": "0.11.2",
    "html-loader": "0.5.1",
    "html-webpack-plugin": "2.30.1",
    "html-webpack-template": "5.6.0",
    "raw-loader": "0.5.1",
    "style-loader": "0.18.2",
    "url-loader": "0.5.9"
  }
}

直接打开命令行,输入 npm run dev 即可看到效果,修改文件,实现浏览器自动刷新。

参考文章 https://www.cnblogs.com/QxQstar/p/5961387.html

 类似资料: