nuxt-modules / mdc

MDC supercharges regular Markdown to write documents interacting deeply with any Vue component.
MIT License
201 stars 22 forks source link

Nuxt Image functionality causes auto-install of NuxtImage module even when NuxtImg is not used #234

Open sebaguse opened 4 months ago

sebaguse commented 4 months ago

I have raised this issue with Nuxt main repo and been adviced this might be a problem with MDC module. The original issue is available here https://github.com/nuxt/nuxt/issues/27854

MDC triggers Nuxt to auto-install NuxtImage despite useNuxtImage being set to false. Daniel Roe suggested:

The way that code is written means it's possible NuxtImage could be used at runtime so it's not possible to tree shake from the bundle, which is why you are being prompted to install it.

harlan-zw commented 4 months ago

A simple solution to solve this would be to break the build-time plugin which transforms the resolveComponent into an explicit import.

// String() breaks the build-time transform because it's considered dynamic 
const imgComponent = useRuntimeConfig().public.mdc.useNuxtImage ? resolveComponent(String('NuxtImg')) : 'img'

But I'm not sure if this will break NuxtImg being resolved properly, so a solution is a build-time template that returns the image component instance.

I don't have the capacity to investigate further at the moment if anyone else wants to take this up.

sebaguse commented 3 months ago

any update on this, please?

timelytree commented 1 month ago

CC @antfu @farnabaz, any ideas on what to do here? This is proving to be really annoying for DX, and I've got members of my team continuously accidentally installing NuxtImg, even though we don't use it.