nuxt / image

Plug-and-play image optimization for Nuxt applications.
https://image.nuxt.com
MIT License
1.36k stars 273 forks source link

How to share provider through nuxt layer? #744

Closed KeJunMao closed 1 year ago

KeJunMao commented 1 year ago
// my-layer/nuxt.config.ts
...
  image: {
    providers: {
      alioss: {
        name: 'alioss',
        provider: './providers/alioss',
        options: {},
      },
    },
  },
...

// my-layer/providers/alioss.ts
import type { ProviderGetImage } from '@nuxt/image-edge'
import { joinURL, withHttp, withHttps } from 'ufo'
export const getImage: ProviderGetImage = () => {}
// app/nuxt.config.ts 
...
extends: ['my-layer'],
...
 ERROR  5:00:42 PM [vite] Internal server error: Failed to resolve import "app/providers/alioss" from "virtual:nuxt:app/.nuxt/image-options.mjs". Does the file exist?

Do I have to copy /providers/alioss.ts for each app?

KeJunMao commented 1 year ago
import { createResolver } from '@nuxt/kit'
const { resolve } = createResolver(import.meta.url)

export default defineNuxtConfig({
  modules: [
    '@nuxt/image-edge',
  ],
  image: {
    providers: {
      alioss: {
        name: 'alioss',
        provider: resolve('./providers/alioss'),
        options: {},
      },
    },
  }
})