@son426/vite-image 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -67,6 +67,31 @@ Just a standard Vite + React project.
67
67
  - react (>= 18.0.0)
68
68
  - react-dom (>= 18.0.0)
69
69
 
70
+ ## TypeScript Setup
71
+
72
+ **⚠️ Temporary Setup Required**: Currently, you need to add type declarations manually. This will be automated in a future update.
73
+
74
+ Add the following to your project's type definition file (e.g., `src/vite-env.d.ts`):
75
+
76
+ ```typescript
77
+ /// <reference types="vite/client" />
78
+
79
+ interface ResponsiveImageData {
80
+ src: string;
81
+ width: number;
82
+ height: number;
83
+ srcSet?: string;
84
+ blurDataURL?: string;
85
+ }
86
+
87
+ declare module "*?vite-image" {
88
+ const content: ResponsiveImageData;
89
+ export default content;
90
+ }
91
+ ```
92
+
93
+ This ensures TypeScript recognizes `?vite-image` imports. Sorry for the temporary manual step—we're working on automating this.
94
+
70
95
  ## Usage
71
96
 
72
97
  ### 1. Setup Vite Plugin
@@ -159,12 +184,29 @@ viteImage({
159
184
  },
160
185
  });
161
186
 
187
+ // Add type declarations for autoApply extensions
188
+ // In your project's vite-env.d.ts or a custom .d.ts file:
189
+ // (Make sure you've already added the ResponsiveImageData interface from the TypeScript Setup section above)
190
+
191
+ declare module "*.jpg" {
192
+ const imageData: ResponsiveImageData;
193
+ export default imageData;
194
+ }
195
+
196
+ declare module "*.png" {
197
+ const imageData: ResponsiveImageData;
198
+ export default imageData;
199
+ }
200
+
162
201
  // Component
163
202
  import bgImage from "@/assets/background.jpg"; // No query needed
164
203
  <Image src={bgImage} alt="Background" />;
165
204
  ```
166
205
 
167
- **Important**: The `src` prop must receive the imported object directly. String URLs are not supported.
206
+ **Important**:
207
+
208
+ - The `src` prop must receive the imported object directly. String URLs are not supported.
209
+ - When using `autoApply`, you need to add type declarations for the extensions you're using in your project's type definition file (e.g., `vite-env.d.ts`).
168
210
 
169
211
  The `?vite-image` query (or autoApply) automatically generates:
170
212
 
@@ -293,9 +335,11 @@ Type definitions are included. The package also extends vite-imagetools types fo
293
335
 
294
336
  ```typescript
295
337
  import Image from "@son426/vite-image/react";
296
- import type { ImageProps, ResponsiveImageData } from "@son426/vite-image/react";
338
+ import type { ImageProps } from "@son426/vite-image/react";
297
339
  ```
298
340
 
341
+ **Note**: After setting up the type declarations in the "TypeScript Setup" section above, you can use `ResponsiveImageData` directly in your code without importing it.
342
+
299
343
  ## How It Works
300
344
 
301
345
  1. **Image Processing**: When you import an image with `?vite-image` query or via `autoApply`, the plugin automatically generates:
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { ImageProps } from './react/index.js';
2
1
  export { A as AutoApplyConfig, R as ResponsiveImageData, V as ViteImageConfig } from './types-B08JIQxT.js';
2
+ export { ImageProps } from './react/index.js';
3
3
  export { ViteImagePluginOptions, viteImage } from './plugin/index.js';
4
+ import 'vite-imagetools';
4
5
  import 'react/jsx-runtime';
5
6
  import 'react';
6
- import 'vite-imagetools';
7
7
  import 'vite';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@son426/vite-image",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "A Vite plugin and React component for optimized images with LQIP support using vite-imagetools",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",