webpack自动打包出现localhost:8080只有Cannot GET /错误

自动打包出现这个,这不是我门预期的

const path = require('path')

module.exports = {
    //编译模式
    mode:'development',  //development production
    entry:path.join(__dirname,'./src/index.js'),
    output:{
        path:path.join(__dirname,'./dist'),  //输出文件的存放路径
        filename:'bundle.js'  //输出文件的名称
    },

解决方案:加入devServer

const path = require('path')

module.exports = {
    //编译模式
    mode:'development',  //development production
    entry:path.join(__dirname,'./src/index.js'),
    output:{
        path:path.join(__dirname,'./dist'),  //输出文件的存放路径
        filename:'bundle.js'  //输出文件的名称
    },
    devServer: {
        //....//
        static: {                               
          directory: path.join(__dirname, './'),  
          watch: true
        }
     }
}

npm run dev

运行成功

原文地址:https://www.cnblogs.com/hechunfeng/p/15732784.html