webpack处理跨域
代理,重定向
1
2
3
4
5
6
7
8
9
10devServer: {
proxy: {
'/api': { // 捕获路径
target: 'http://localhost:3000', // 重定向
pathRewrite: {
api: '' // 重写path
}
}
}
}前端mock数据模拟
1
2
3
4
5
6
7devServer: {
before(app) {
app.get('/api/user', (req, res) => {
res.end('hello')
})
}
}服务端运行
webpack-dev-middleware
1
2
3
4
5
6const WebpackDevMiddleware = require('webpack-dev-middleware')
const config = require('./webpack.config')
const compiler = webpack(config)
app.use(WebpackDevMiddleware(compiler))