nuxt/icon

"serverBundle: auto" seems not work on cloudflare

HADB opened this issue · 6 comments

HADB commented

I'm using Cloudflare Pages GitHub/GitLab integration, and the log shows "[info] Nuxt Icon server bundle mode is set to local" when building which causes the bundle size exceed the 25M limit. It should be remote as the document saying.

It works fine if I set serverBundle to remote manually.

Could you help checking how we could improve the detection logic here? I don't use CF a lot to know all the gotchas.

icon/src/module.ts

Lines 66 to 70 in ec95615

serverBundle = nuxt.options.dev
? 'local'
: KEYWORDS_EDGE_TARGETS.some(word => typeof nuxt.options.nitro.preset === 'string' && nuxt.options.nitro.preset.includes(word))
? 'remote'
: 'local'

HADB commented

OK, I will try today.

HADB commented

@antfu Hi, I figured out the problem and created a PR here #216 , please have a look.

The problem is that nuxt.options.nitro.preset was undefined in my cloudflare build environment with zero-config support of nitro, but there's a environment variable NITRO_PRESET:"cloudflare_pages" we can use to detect the preset just as nitro doing itself: unjs/nitro: src/core/config/loader.ts

Is this actually fixed? I am on latest 1.4.5 and my bundle size just went up from 2MB to more than 25 MB and deployments now fail.

[info] Nuxt Icon server bundle mode is set to `local`
[success] Nuxt Icon discovered local-installed 9 collections: bi, carbon, heroicons, hugeicons, logos, material-symbols, ri, solar, tabler

Btw. From this icons I only use 3 (bi, hugeicons and solar), I dont know why it says 9.

HADB commented

@MickL try this command: NITRO_PRESET=cloudflare_pages pnpm build in build configurations.

I tried. Seems to work with 1.4.6 that was released yesterday.