Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

子应用资源请求地址是主应用地址 #3035

Closed
ooo123zzl opened this issue Jan 14, 2025 · 1 comment
Closed

子应用资源请求地址是主应用地址 #3035

ooo123zzl opened this issue Jan 14, 2025 · 1 comment

Comments

@ooo123zzl
Copy link

`"qiankun": "^2.10.16",

主应用为vite+vue3 地址为http://localhost:8000,子应用为cra构建的react18,地址为http://localhost:3000
访问子应用时不能加载antd组件,删除antd组件也不能正确加载样式(只有基本的html),并且图片资源的请求地址是http://localhost:8000/xxx(两个项目有相同名字的图片)
子应用已经在indexjs入口文件设置了__webpack_public_path__和路由basename
子应用config-overrides.js重写的相关配置如下
config => {
// 设置输出为 UMD 格式,以便 Qiankun 能够正确加载生命周期函数
config.output.library = 'reactApp' // 子应用的名称,与你在主应用中注册的名称一致
config.output.libraryTarget = 'umd'
config.output.chunkLoadingGlobal = webpackJsonp_reactApp // 避免与主应用的 Webpack JSONP 函数冲突

    // 配置 Polyfill
    config.resolve.fallback = {
        ...config.resolve.fallback,
        fs: false,
        path: require.resolve('path-browserify'),
        crypto: require.resolve('crypto-browserify'),
        stream: require.resolve('stream-browserify'),
        buffer: require.resolve('buffer/')
        // 根据需要添加更多模块
    }

    // 提供全局变量
    config.plugins.push(
        new webpack.ProvidePlugin({
            Buffer: ['buffer', 'Buffer']
        })
    )

    // 修改 devServer 配置以支持 CORS
    if (config.devServer) {
        config.devServer.headers = {
            'Access-Control-Allow-Origin': '*'
        }
        config.devServer.historyApiFallback = true // 支持前端路由
    }

    return config
}
Copy link

由于缺乏足够的信息(github、stackblitz、codesandbox等可复现仓库),我们暂时关闭了该 Issue。请修改(不要回复) Issue 提供最小重现以重新开启。谢谢。如果只是单独的技术咨询,可移步 https://qiankun.umijs.org/#-community 交流~

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant