image icon indicating copy to clipboard operation
image copied to clipboard

Provider for dev/build only

Open pkpowell opened this issue 3 years ago • 1 comments

Is it possible to save images from a provider like sanity to the dist folder on build? Or would that result in more bandwidth longterm?

pkpowell avatar Aug 24 '21 10:08 pkpowell

I would advise against it, personally, for exactly that reason. But it would be possible to do that using a custom static provider, for example:

export default {
  target: 'static',
  buildModules: ['@nuxt/image'],
  image: {
    providers: {
      custom: {
        provider: '~/providers/sanity-static',
        options: {
          projectId: 'YOUR_PROJECT_ID'
        }
      },
    },
    provider: 'custom',
  }
};

Then with a providers/sanity-static.js file:

import { getImage as _getImage } from '@nuxt/image/dist/runtime/providers/sanity'

export const getImage = (src, options, ctx) => ({
  ..._getImage(src, options, ctx),
  isStatic: true
})

danielroe avatar Aug 24 '21 11:08 danielroe