Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use NuxtImg component in ProseImg if the @nuxt/image module is activated #180

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion playground/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
v-if="body"
:body="body"
:data="data"
:prose="false"
/>
</article>
</MDC>
Expand Down
8 changes: 7 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineNuxtModule, extendViteConfig, addComponent, addComponentsDir, createResolver, addServerHandler, addTemplate, addImports, addServerImports } from '@nuxt/kit'
import { defineNuxtModule, extendViteConfig, addComponent, addComponentsDir, createResolver, addServerHandler, addTemplate, addImports, addServerImports, hasNuxtModule } from '@nuxt/kit'
import fs from 'fs'
import type { ModuleOptions } from './types'
import { defu } from 'defu'
Expand Down Expand Up @@ -165,6 +165,12 @@ export default defineNuxtModule<ModuleOptions>({
})
}

if (hasNuxtModule('@nuxt/image')) {
nuxt.options.runtimeConfig.public.mdc = defu(nuxt.options.runtimeConfig.public.mdc, {
useNuxtImage: true
})
}

// Update Vite optimizeDeps
extendViteConfig((config) => {
const include = [
Expand Down
9 changes: 6 additions & 3 deletions src/runtime/components/prose/ProseImg.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<template>
<img
<component
:is="imgComponent"
:src="refinedSrc"
:alt="alt"
:width="width"
:height="height"
>
/>
</template>

<script setup lang="ts">
import { withTrailingSlash, withLeadingSlash, joinURL } from 'ufo'
import { useRuntimeConfig, computed } from '#imports'
import { useRuntimeConfig, computed, resolveComponent } from '#imports'

const imgComponent = useRuntimeConfig().public.mdc.useNuxtImage ? resolveComponent('NuxtImg') : 'img'

const props = defineProps({
src: {
Expand Down