Skip to content

Commit

Permalink
Allow importing Image component from @astrojs/image (#3848)
Browse files Browse the repository at this point in the history
* Allow importing Image component from @astrojs/image

* Adds a changeset

* Export the Image type
  • Loading branch information
matthewp committed Jul 7, 2022
1 parent 568960f commit 502f063
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/nervous-swans-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'astro': patch
'@astrojs/image': patch
---

Allow importing the Image component from @astrojs/image
2 changes: 2 additions & 0 deletions packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export async function createVite(
replacement: fileURLToPath(new URL('../@types/astro', import.meta.url)),
},
],
conditions: ['astro'],
},
// Note: SSR API is in beta (https://vitejs.dev/guide/ssr.html)
ssr: {
Expand All @@ -129,6 +130,7 @@ export async function createVite(
result = vite.mergeConfig(result, astroConfig.vite || {});
result = vite.mergeConfig(result, commandConfig);
sortPlugins(result);

return result;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/integrations/image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default {

```html
---
import { Image } from '@astrojs/image/components';
import { Image } from '@astrojs/image';
import heroImage from '../assets/hero.png';
---

Expand All @@ -136,7 +136,7 @@ import heroImage from '../assets/hero.png';

```html
---
import { Image } from '@astrojs/image/components';
import { Image } from '@astrojs/image';

const imageUrl = 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png';
---
Expand All @@ -162,7 +162,7 @@ const imageUrl = 'https://www.google.com/images/branding/googlelogo/2x/googlelog
```html
---
setup: |
import { Image } from '@astrojs/image/components'
import { Image } from '@astrojs/image'
import hero from '../../assets/blog/introducing-astro.jpg'
title: Hello world!
publishDate: 12 Sep 2021
Expand Down
5 changes: 4 additions & 1 deletion packages/integrations/image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
"bugs": "https://github.com/withastro/astro/issues",
"homepage": "https://astro.build",
"exports": {
".": "./dist/index.js",
".": {
"astro": "./components/index.js",
"import": "./dist/index.js"
},
"./sharp": "./dist/loaders/sharp.js",
"./endpoints/dev": "./dist/endpoints/dev.js",
"./endpoints/prod": "./dist/endpoints/prod.js",
Expand Down
1 change: 1 addition & 0 deletions packages/integrations/image/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './index';
export type { Image } from '../components/index';

export type InputFormat =
| 'heic'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import socialJpg from '../assets/social.jpg';
import { Image } from '@astrojs/image/components';
import { Image } from '@astrojs/image';
---

<html>
Expand Down
4 changes: 3 additions & 1 deletion packages/integrations/image/test/image-ssg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect } from 'chai';
import * as cheerio from 'cheerio';
import path from 'path';
import sizeOf from 'image-size';
import { fileURLToPath } from 'url';
import { loadFixture } from './test-utils.js';

let fixture;
Expand All @@ -12,7 +13,8 @@ describe('SSG images', function () {
});

function verifyImage(pathname, expected) {
const dist = path.join('test/fixtures/basic-image/dist', pathname);
const url = new URL('./fixtures/basic-image/dist/' + pathname, import.meta.url);
const dist = fileURLToPath(url);
const result = sizeOf(dist);
expect(result).to.deep.equal(expected);
}
Expand Down

0 comments on commit 502f063

Please sign in to comment.