ant-design / ant-design-pro

👨🏻‍💻👩🏻‍💻 Use Ant Design like a Pro!
https://pro.ant.design
MIT License
36.31k stars 8.14k forks source link

🐛 [BUG]通过npm run build生成的index.html入口文件中,使用了绝对地址. #11211

Open windqyoung opened 4 months ago

windqyoung commented 4 months ago

🐛 bug 描述

在文件config/config.tx中设置 publicPath: process.env.NODE_ENV === 'production' ? './' : '/', 执行 npm run build 后, index.html文件中, 有一行代码是 <script async src="/scripts/loading.js"></script>, 在非根目录部署的情况下, 无法加载这个文件

📷 复现步骤 | Recurrence steps

同bug描述, 直接build就是结果.

🏞 期望结果 | Expected results

index.html中应该是 <script async src="./scripts/loading.js"></script>

💻 复现代码 | Recurrence code

© 版本信息

🚑 其他信息

wsafight commented 1 month ago

我也遇到这个问题,这里需要配置 headScripts 项目。 代码如下所示:

  headScripts: [
    // 解决首次加载时白屏的问题
    { src: `${PUBLIC_PATH}${PUBLIC_PATH.endsWith('/') ? '' : '/'}scripts/loading.js`, async: true },
  ],

我这边觉得 ant-design-pro 不会解决这个问题,毕竟 headScripts 里面也可能去配置其他 cdn 的脚本等。所以可能需要你手动修改