Rebuild images to nuxt-image

Settings and examples for rebuilding to nuxt-image.

Settings

It requires nuxt-image provider settings.

nuxt.config.js
{
  image: {
    imgix: {
      baseURL: "https://images.microcms-assets.io/",
    },
  },
}

And rehype-image-salt settings.

nuxt.config.js
{
  content: {
    markdown: {
      rehypePlugins: [
        [
          "@hankei6km/rehype-image-salt",
          {
            baseURL: "https://images.microcms-assets.io/",
            rebuild: {
              tagName: "nuxt-img",
              baseAttrs: 'provider="imgix" data-salt-q=""',
            },
          },
        ],
      ],
    },
  }
}
  • baseURLfromprovider settings

  • tagName isnuxt-imgornuxt-picture

  • baseAttrs isprovider="imgix" data-salt-q=""

    • provider to select Provider
    • data-salt-q remove query parameters by CMS added(it conflict to nuxt-image)
    • If there is a default value for the entire content, it is also available(ie. fit sizes modifiers)

Examples

sizes

![林道](https://...image.jpg){
  width="600" height="337"
  sizes="sm:100vw md:50vw lg:400px"
}

林道

fit

![林道](https://...image.jpg){
  width="200" height="400"
  fit="cover"
}

林道

imgix best practices

![Man Using Laptop](https://...image.jpg){
  width="300" height="500"
  fit="cover"
  modifiers="auto=format,compress&crop=faces"
}

![Woman Holding Macbook](https://...image.jpg){
  width="300" height="500"
  fit="cover"
  modifiers="auto=format,compress&crop=faces"
}

Man Using Laptop

Woman Holding Macbook

You can easily write an image that applied "imgix best practices" style using baseAttrs.

Credits

Edit this page on GitHub Updated at Tue, Dec 21, 2021