Solve the problem that webpack-dev-server cannot be accessed through localhost

 Problem : When learning webpack, the following problems occurred. When installing and running webpack-dev-server, the browser cannot access normally and throws 404.

Solution : Add relevant settings in webpack.config.js

module.exports={
 
    mode:'development',
    
    devServer: {
        static:'./',//根目录,需要点击进入src才能查看
        //static:path.join(__dirname, 'src'),//可以直接访问到src页面,实现页面的实时查看。
        host: "localhost",
        port: 8080,
        hot: true,
    },
}

success:

 See another article for details

Why use webpack? _Kaka Bear's Blog-CSDN Blog

Guess you like

Origin blog.csdn.net/qq_41045128/article/details/125437754