美文网首页
webpack 开发阶段跨域处理

webpack 开发阶段跨域处理

作者: 苍老师的眼泪 | 来源:发表于2022-05-03 18:32 被阅读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(),
    ],

}

小心重定向缓存

相关文章

网友评论

      本文标题:webpack 开发阶段跨域处理

      本文链接:https://www.haomeiwen.com/subject/sqliyrtx.html