ice icon indicating copy to clipboard operation
ice copied to clipboard

ice.config.mts 中 publicPath 引入环境变量打包结果不对

Open jht-llhy opened this issue 9 months ago • 6 comments

Describe the bug

我在ice.config.mts 中 写的publicPath: process.env.ICE_PUBLIC_PATH,在ice start --speedup后ice build --mode production,在打包结果中其他环境变量都正确,只有这个变量经常性的依然是develop的变量

Expected behavior

ice build --mode production时应该取.env.production文件中的值

Actual behavior

No response

Version of ice.js

@ice/app @3.4.7

Content of build.json or ice.config.mts


Additional context

No response

jht-llhy avatar Mar 26 '25 09:03 jht-llhy

https://github.com/alibaba/ice/issues/6696 和这个应该是一个问题吧,在修改ice.config.mts文件后重新打包,有概率会打包正确,可能是缓存问题?

jht-llhy avatar Mar 26 '25 12:03 jht-llhy

可以通过 npm start -- --force 确认下是不是缓存引起的问题

ClarkXia avatar Mar 27 '25 02:03 ClarkXia

感谢关注,目前在start时没有这个问题,仅在build时存在该问题。我再详细描述一下操作流程 1、由于项目需要在测试环境和生产环境的路径不同,因此我将ice.config.mts中的publicPath设置为process.env.ICE_PUBLIC_PATH; 2、运行npm run build 即 ice build --mode development,在打包产物中全局搜索develop环境的 ICE_PUBLIC_PATH ,数量为22; 3、再次运行npm run pro-build 即 ice build --mode production,在打包产物中全局搜索develop环境的 ICE_PUBLIC_PATH ,数量为15,均存在于css文件中,我的css有background:url('@/assets/header-bg.png')、background:url('../../assets/header-bg.png')的写法; 4、再次运行npm run pro-build 即 ice build --mode production 或 手动修改 ice.config.mts 文件,有可能会打包正确。

jht-llhy avatar Mar 27 '25 03:03 jht-llhy

可以提供下复现的 case,我们定位下

ClarkXia avatar Apr 03 '25 02:04 ClarkXia

ice-app.zip ice.config.mts修改了publicPath为process.env.ICE_PUBLIC_PATH,先打包develop,紧接着打包production,在打包产物中,写在less文件中的@/assets/header-bg.png、@/assets/yshxt.otf文件的前缀没有被替换为production的

jht-llhy avatar Apr 07 '25 03:04 jht-llhy

Image

jht-llhy avatar Apr 07 '25 03:04 jht-llhy