Add @astrojs/image to the project

This commit is contained in:
Konrad Szwarc 2022-08-28 16:58:55 +02:00
parent 44fc296f6f
commit 6252066a9e
8 changed files with 758 additions and 58 deletions

View file

@ -56,10 +56,13 @@
"globals": { "globals": {
"astroHTML": true "astroHTML": true
}, },
"extends": ["airbnb/base", "airbnb-typescript/base", "plugin:astro/all"], "extends": ["airbnb/base", "airbnb-typescript/base", "plugin:astro/all", "plugin:astro/jsx-a11y-strict"],
"parser": "astro-eslint-parser", "parser": "astro-eslint-parser",
"parserOptions": { "parserOptions": {
"parser": "@typescript-eslint/parser" "parser": "@typescript-eslint/parser"
},
"rules": {
"astro/jsx-a11y/alt-text": [2, { "img": ["Image", "Picture"] }]
} }
}, },
{ {

View file

@ -1,10 +1,11 @@
import image from '@astrojs/image';
import react from '@astrojs/react'; import react from '@astrojs/react';
import tailwind from '@astrojs/tailwind'; import tailwind from '@astrojs/tailwind';
import { defineConfig } from 'astro/config'; import { defineConfig } from 'astro/config';
// https://astro.build/config // https://astro.build/config
export default defineConfig({ export default defineConfig({
integrations: [react(), tailwind()], integrations: [react(), tailwind(), image()],
vite: { vite: {
ssr: { ssr: {
external: ['svgo'], external: ['svgo'],

793
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -14,6 +14,7 @@
"build-storybook": "build-storybook" "build-storybook": "build-storybook"
}, },
"dependencies": { "dependencies": {
"@astrojs/image": "0.3.6",
"astro-icon": "0.7.3", "astro-icon": "0.7.3",
"clsx": "1.2.1", "clsx": "1.2.1",
"prettier-plugin-astro": "0.5.3", "prettier-plugin-astro": "0.5.3",

View file

@ -1,8 +1,11 @@
--- ---
import { Image } from '@astrojs/image/components';
import SectionCard from '@/atoms/section-card.astro'; import SectionCard from '@/atoms/section-card.astro';
import type { MainSection } from '@/types/main-section'; import type { MainSection } from '@/types/main-section';
export interface Props extends MainSection {} export interface Props extends MainSection {}
const { image } = Astro.props;
--- ---
<SectionCard>Main section</SectionCard> <SectionCard>Main section <Image src={image.src} alt={image.alt} width={200} height={200} format="webp" /></SectionCard>

View file

@ -1,4 +1,3 @@
import myImage from '@/assets/my-image.jpeg';
import type { Data } from '@/types/data'; import type { Data } from '@/types/data';
const data: Data = { const data: Data = {
@ -11,7 +10,7 @@ const data: Data = {
config: { config: {
icon: 'fa6-solid:user', icon: 'fa6-solid:user',
}, },
image: { src: myImage, alt: 'Mark Freeman picture' }, image: { src: import('@/assets/my-image.jpeg'), alt: 'Mark Freeman picture' },
fullName: 'Mark Freeman', fullName: 'Mark Freeman',
role: 'Senior React Developer', role: 'Senior React Developer',
details: [ details: [

2
src/env.d.ts vendored
View file

@ -1 +1 @@
/// <reference types="astro/client" /> /// <reference types="@astrojs/image/client" />

View file

@ -1,7 +1,9 @@
import type { ImageMetadata } from '@astrojs/image';
export type Icon = string; export type Icon = string;
export type LocalImage = { export type LocalImage = {
src: string; src: Promise<{ default: ImageMetadata }>;
alt: string; alt: string;
}; };