webpack4.0-WebpackDevServer实现转发请求-14

// 更多配置查看webpack官网
devServer: {
        contentBase: './dist',
        port: 8090,
        open: true,
        hotOnly: true, // 当页面数据变化时,实时更新
        proxy: {
            // index:'', // 当要代理的不是 /react/api这种类似的,而是代理的 / 根路径 那么 这时必须配置  index: ''
            '/react/api': {
                target:'http://www.dell-lee.com', // 当请求是 /react/api的时候能够将请求代理到 http://www.dell-lee.com 当为https的时候需要配置secure选项为false
                secure: false, // 当转发的请求为https时secure配置为 false
                pathReWrite: {
                    'header.json': 'demo.json' // 当请求是去拿 header.json的时候,实际是去拿demo.json用于接口数据模拟的时候
                },
                changeOrigin: true // 突破浏览器对origin的限制
            }
        }
    },
发布了116 篇原创文章 · 获赞 9 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/memedadexixaofeifei/article/details/103909851