分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

webpack自带的跨域代理配置

发布时间:2023-09-06 02:17责任编辑:熊小新关键词:配置webpack跨域

问题:开发过程中难免有跨域的问题。

解决:webpack代理的配置

const path = require(‘path‘);const HtmlWebpackPlugin = require(‘html-webpack-plugin‘);const ExtractTextPlugin = require(‘extract-text-webpack-plugin‘);const webpack = require(‘webpack‘);module.exports = {entry: ‘./src/app.jsx‘,output: {path: path.resolve(__dirname, ‘dist‘),filename: ‘js/app.js‘,publicPath: "/dist/"},resolve: {alias : {page : path.resolve(__dirname, ‘src/page‘),component : path.resolve(__dirname, ‘src/component‘),util : path.resolve(__dirname, ‘src/util‘),service : path.resolve(__dirname, ‘src/service‘),}},module: {rules: [//jsx{test: /\.jsx$/,exclude: /(node_modules)/,use: {loader: ‘babel-loader‘,options: {presets: [‘env‘,‘react‘]//根据环境打包(浏览器,node)}}},//css{test: /\.css$/,use: ExtractTextPlugin.extract({fallback: "style-loader",use: "css-loader"}) ??????},//sass{test: /\.scss$/,use: ExtractTextPlugin.extract({fallback: ‘style-loader‘,use: [‘css-loader‘, ‘sass-loader‘]})},//图片的配置{test: /\.(png|jpg|gif)$/i,use: [{loader: ‘url-loader‘,options: {limit: 8192,name:‘resource/[name].[ext]‘}}]},//字体的配置{test: /\.(otf|eot|svg|ttf|woff|woff2)$/i,use: [{loader: ‘url-loader‘,options: {limit: 8192,name:‘resource/[name].[ext]‘}}]}]},plugins: [//处理css文件new HtmlWebpackPlugin({template:‘./src/index.html‘,favicon:‘./favicon.ico‘}),//独立cssnew ExtractTextPlugin("css/[name].css"),//参数为生成css的位置//提取公共模块new webpack.optimize.CommonsChunkPlugin({//webpack自带插件,不用安装name:‘common‘,filename:‘js/base.js‘})],devServer: {// contentBase: path.join(__dirname, ‘dist‘),port: 9999,historyApiFallback:{index : ‘/dist/index.html‘//404},proxy : {‘/manage‘ : {target : ‘http://admintest.happymmall.com‘,changeOrigin : true}}}};

  

webpack自带的跨域代理配置

原文地址:https://www.cnblogs.com/ipoodle/p/9750791.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved