yarn add webpack-dev-server

    1. const Webpack = require('webpack')
    2. module.exports = {
    3. devServer: {
    4. contentBase: './public', // 为devServer指定静态资源目录(不包括打包资源),如public/favor.icon,可以接受字符串,也可以接受一个数组,数组中存放目录
    5. // hot: true, // 开启热更新 如果有文件发生改动,热更新失败,则会自动回退到自动刷新页面,会导致捕捉不到错误
    6. hotOnly: true, // 如果改成hotOnly,有文件发生改动,热更新失败,则不会回退到自动刷新页面,能更好的帮我们定位错误
    7. proxy: {
    8. '^/api': {
    9. // http://localhost:8080/api/users => https://api.github.com/api/users
    10. target: 'https://api.github.com',
    11. pathRewrite: {
    12. '^/api': '' // https://api.github.com/api/users => https://api.github.com/users
    13. },
    14. changeOrigin: true
    15. }
    16. }
    17. },
    18. plugins: [
    19. new Webpack.HotModuleReplacementPlugin()
    20. ]
    21. }