webpack-dev-server找不到模块的问题
使用webpack-dev-server 正确配置,环境确跑不起来
报错
webpack.config.js
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
mode: "development",
entry: path.join(__dirname,'src','index.js'),
output: {
path: path.join(__dirname,'dist'),
filename: "bundle.js"
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname,'src','index.html'),
filename: "index.html"
})
],
devServer: {
port: 3000,
contentBase: path.join(__dirname,'dist')
}
}
package.json
{
"name": "webpack-demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --config webpack.config.js",
"dev": "webpack-dev-server"
},
"author": "",
"license": "ISC",
"dependencies": {
"html-webpack-plugin": "^5.2.0",
"webpack": "^5.24.2",
"webpack-cli": "^4.5.0"
},
"devDependencies": {
"webpack-dev-server": "^3.11.2"
}
}
参照:https://github.com/webpack/webpack-dev-server/issues/2759
将package.json中的 "dev": "webpack-dev-server" 改为 "dev": "webpack serve"完美解决