ant-design-pro icon indicating copy to clipboard operation
ant-design-pro copied to clipboard

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

Open windqyoung opened this issue 10 months ago • 1 comments

🐛 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

© 版本信息

  • Ant Design Pro 版本: [e.g. 4.0.0]
  • umi 版本
  • 浏览器环境
  • 开发环境 [e.g. mac OS]

🚑 其他信息

windqyoung avatar Apr 15 '24 09:04 windqyoung

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

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

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

wsafight avatar Jul 16 '24 12:07 wsafight