- 基于creact-react-app react-app-rewired搭建的项目
- 解决多个跨域问题
- 在package.json文件配置跨域不生效问题
const {
override,
addPostcssPlugins,
fixBabelImports,
overrideDevServer
} = require('customize-cra');
const path = require('path');
const webpack = require('webpack');
const ENV = {
DEV: 'http://a.dev.example.com/',
PROD: 'http://a.pro.example.com/'
};
const SECOND_ENV = {
DEV: 'http://b.dev.example.com/',
PROD: 'http://b.pro.example.com/'
};
const devServerConfig = () => config => {
return {
...config,
proxy: {
'/api': {
target: ENV.DEV,
changeOrigin: true,
secure: false
},
'/bpi': {
target: SECOND_ENV.DEV,
changeOrigin: true,
secure: false
},
'/capi':{
target: 'http://c.dev.example.com',
changeOrigin: true,
secure: false,
pathRewrite: {
'^/capi': ''
}
},
}
};
};
process.env.GENERATE_SOURCEMAP = process.env.NODE_ENV === 'development' ? 'true' : 'false';
module.exports = {
webpack: override(
addPostcssPlugins([
require('postcss-normalize')({
forceImport: true
}),
require('postcss-preset-env')({
stage: 0
})
]),
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
style: 'css'
})
),
devServer: overrideDevServer(devServerConfig())
};