参考地址:https://www.cnblogs.com/zdz8207/p/vue-webpack-dev-server.html
版本:
直接安装webpack-dev-server 对应的最新版本为@4.3.1,npm run dev时会报错:
node_modules\_webpack-dev-server@4.3.1@webpack-dev-server\lib\servers\WebsocketServer.js:10 static heartbeatInterval = 1000; ^ SyntaxError: Unexpected token = at new Script (vm.js:83:7) at NativeCompileCache._moduleCompile
网上搜索了,说是版本兼容问题,所以尝试降低webpack-dev-server版本为@2.9.1
(1)、npm uninstall webpack-dev-server
(2)、npm install webpack-dev-server@2.9.1
(3)、npm run dev
结果还是报错:(版本过低)
[webpack-cli] You need to install 'webpack-dev-server' for running 'webpack serve'. Error: Cannot find module 'webpack-dev-server/bin/cli-flags'
参考文档将版本升为@3.11.2,结果完美解决
package.json文件
"scripts": { "dev": "webpack serve --progress --config ./webpack.config.js" },