首页 > 代码库 > 用webpack-dev-server开发时代理,决解开发时跨域问题

用webpack-dev-server开发时代理,决解开发时跨域问题

需要webpack,webpack-dev-server

npm install webapck webpack-dev-server --save-dev

设置时

devServer: {
        historyApiFallback: true,
          hot: true,
        inline: true,
        stats: { colors: true },
        proxy: {
            ‘/list‘: {
              target: ‘https://api.github.com‘,
              pathRewrite: {‘^/column‘ : ‘/column‘},
              changeOrigin: true
            }
         }
    },

这段代码就是将  ‘/list‘ 通过本地开发服务器webpack-dev-server转发到 ‘https://api.github.com‘
项目地址:https://github.com/fengnovo/diary/tree/master/react/20161021/webpack-dev-server-proxy-test

用webpack-dev-server开发时代理,决解开发时跨域问题