webpack 开发阶段跨域处理

2022-05-03  本文已影响0人  苍老师的眼泪

index.js

fetch('/api/zxcv').then(res => res.json()).then(res => {
    console.log(res)
})

webpack.config.js

const htmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    entry: './src/index.js',

    mode: 'development',

    devServer: {

        proxy: {
            '/api': {
                target: 'http://127.0.0.1:9000',
            }
        }
    },

    plugins: [
        new htmlWebpackPlugin(),
    ],

}

小心重定向缓存

上一篇 下一篇

猜你喜欢

热点阅读