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

Support Brisa JSX Framework #753

Open
aralroca opened this issue Jan 1, 2025 · 0 comments
Open

Support Brisa JSX Framework #753

aralroca opened this issue Jan 1, 2025 · 0 comments

Comments

@aralroca
Copy link

aralroca commented Jan 1, 2025

I see that the implementation with Brisa it looks very simple:

import { transformProps, type UnpicImageProps } from "@unpic/core";

export type ImageProps = UnpicImageProps<JSX.HTMLAttributes<HTMLImageElement>>;

export function Image(props: ImageProps) {
  return <img {...transformProps(props)} />;
}

This is currently working as Server Component to optimize CDN images, ex of usage:

import { Image } from "@/components/image";

export default function Homepage() {
  return (
    <>
      <Image
        src="https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&auto=format&fit=crop&w=900&q=60"
        layout="fullWidth"
        alt=""
        priority
        height={400}
        crossOrigin="anonymous"
        background="auto"
      ></Image>
      <Image
        src="https://cdn.shopify.com/static/sample-images/garnished.jpeg"
        layout="constrained"
        width={800}
        height={600}
        alt="Shopify"
      ></Image>
      <Image
        src="https://bunnyoptimizerdemo.b-cdn.net/bunny7.jpg?width=300"
        width={400}
        height={300}
        layout="fixed"
        alt="Bunny.net"
      ></Image>
    </>
  );
}

Result HTML:

<img alt="" crossorigin="anonymous" loading="eager" fetchpriority="high" role="presentation" style="object-fit:cover;background-image:url(https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=24&amp;q=60);background-size:cover;background-repeat:no-repeat;width:100%;height:400px;" srcset="https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=640&amp;q=60 640w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=750&amp;q=60 750w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=828&amp;q=60 828w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=960&amp;q=60 960w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=1080&amp;q=60 1080w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=1280&amp;q=60 1280w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=1668&amp;q=60 1668w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=1920&amp;q=60 1920w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=2048&amp;q=60 2048w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=2560&amp;q=60 2560w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=3200&amp;q=60 3200w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=3840&amp;q=60 3840w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=4480&amp;q=60 4480w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=5120&amp;q=60 5120w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=6016&amp;q=60 6016w" src="https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;q=60&amp;h=400">

<img alt="Shopify" loading="lazy" decoding="async" sizes="(min-width: 800px) 800px, 100vw" style="object-fit:cover;max-width:800px;max-height:600px;aspect-ratio:1.3333333333333333;width:100%;" srcset="https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=640&amp;height=480 640w,
https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=750&amp;height=563 750w,
https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=800&amp;height=600 800w,
https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=828&amp;height=621 828w,
https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=960&amp;height=720 960w,
https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=1080&amp;height=810 1080w,
https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=1280&amp;height=960 1280w,
https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=1600&amp;height=1200 1600w" src="https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=800&amp;height=600">

<img alt="Bunny.net" loading="lazy" decoding="async" sizes="400px" style="object-fit:cover;width:400px;height:300px;" srcset="https://bunnyoptimizerdemo.b-cdn.net/bunny7.jpg?width=400&amp;aspect_ratio=400%3A300 400w,
https://bunnyoptimizerdemo.b-cdn.net/bunny7.jpg?width=800&amp;aspect_ratio=800%3A600 800w" src="https://bunnyoptimizerdemo.b-cdn.net/bunny7.jpg?width=400&amp;aspect_ratio=400%3A300" width="400" height="300">

The only problem I see is with the integration in this repo as another package because of the workspace resolution with pnpm and the use of vitest, since all the tooling of Brisa is through bun, and the testing is part of brisa/test. Brisa also does not use vite, it uses bun (brisa dev).

See this fork aralroca@b62d099

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant