Optimize images with @astrojs/image

This commit is contained in:
prototypa
2022-08-10 14:19:08 -04:00
parent 0f40bb3874
commit 63e6ee9c05
5 changed files with 833 additions and 12 deletions

View File

@ -2,16 +2,15 @@ import { defineConfig } from "astro/config";
import tailwind from "@astrojs/tailwind";
import sitemap from "@astrojs/sitemap";
import image from "@astrojs/image";
// https://astro.build/config
export default defineConfig({
// Astro uses this full URL to generate your sitemap and canonical URLs in your final build
site: "https://astrowind.vercel.app/",
integrations: [
tailwind({
integrations: [tailwind({
config: {
applyBaseStyles: false,
},
}),
sitemap({}),
],
applyBaseStyles: false
}
}), sitemap({}), image()]
});

819
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,7 @@
"preview": "astro preview"
},
"devDependencies": {
"@astrojs/image": "^0.3.3",
"@astrojs/sitemap": "^1.0.0",
"@astrojs/tailwind": "^1.0.0",
"astro": "^1.0.0"

View File

Before

Width:  |  Height:  |  Size: 620 KiB

After

Width:  |  Height:  |  Size: 620 KiB

View File

@ -1,5 +1,6 @@
---
const { } = Astro.props;
import { Picture } from '@astrojs/image/components';
const { } = Astro.props;
---
<section>
@ -30,9 +31,10 @@
</div>
</div>
<div>
<div class="relative flex justify-center mb-8 ">
<div class="relative flex justify-center mb-8">
<div class="flex flex-col justify-center">
<img class="mx-auto rounded-md" src="/images/hero-astro.jpg" width="768" height="432" alt="Hero">
<Picture src={import('~/assets/hero-astro.jpg')} class="mx-auto rounded-md" widths={[400, 768]}
sizes="(max-width: 768px) 100vw, 768px" alt="Hero Image" aspectRatio="16:9" />
</div>
</div>
</div>