Git Product home page Git Product logo

vite-plugin-thumbhash's Introduction

vite-plugin-thumbhash

Add ThumbHash to your vite project.

Install

npm install vite-plugin-thumbhash --save-dev
pnpm add vite-plugin-thumbhash -D

Usage

import { defineConfig } from 'vite'
import { thumbHash } from 'vite-plugin-thumbhash'

export default defineConfig({
  plugins: [thumbHash()]
})
import Image from 'example.jpg?thumb'

//...
<img src={Image.thumbSrc}
     width={Image.thumbWidth}
     height={Image.thumbHeight}
/>


// If you want to import original image
<img src={Image.originalSrc}
     width={Image.originalWidth}
     height={Image.originalHeight}
/>

TypeScript IntelliSense

Add the following code to vite-env.d.ts :

/// <reference types="vite-plugin-thumbhash/client" />

Options

type Options =
    {
      /**
       * A picomatch pattern, or array of patterns, 
       * which specifies the files in the build the plugin should operate on. 
       */
      include?: Array<string | RegExp> | string | RegExp
      /**
       * A picomatch pattern, or array of patterns,
       * which specifies the files in the build the plugin should ignore.
       */
      exclude?: Array<string | RegExp> | string | RegExp
      /**
       * type OutputExtension = 'png' | 'jpg' | 'webp' | 'avif'
       * @default: 'png'
       */
      outputExtension?: OutputExtension
    }

Example

see playground

License

MIT Β© nemurubaka

vite-plugin-thumbhash's People

Contributors

cijiugechu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vite-plugin-thumbhash's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency prettier to v2.8.8
  • fix(deps): update dependency @napi-rs/canvas to v0.1.52
  • fix(deps): update dependency thumbhash-node to v0.1.3
  • chore(deps): update dependency @types/node to v18.19.33
  • chore(deps): update dependency tsup to v6.7.0
  • chore(deps): update dependency typescript to v5.4.5
  • fix(deps): update dependency @rollup/pluginutils to v5.1.0
  • chore(deps): update pnpm/action-setup action to v4
  • πŸ” Create all rate-limited PRs at once πŸ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v2
  • pnpm/action-setup v2.0.1
  • actions/setup-node v2
  • actions/cache v3
npm
package.json
  • prettier ^2.8.1
  • tsup ^6.5.0
  • typescript ^4.9.5
  • vitest ^0.28.4
packages/core/package.json
  • @rollup/pluginutils ^5.0.2
  • @napi-rs/canvas ^0.1.41
  • thumbhash-node ^0.1.1
  • @types/node ^18.11.18
  • benny ^3.7.1
  • thumbhash ^0.1.1
  • tsup ^6.7.0
  • typescript ^5.1.3
  • vite ^4.2.0
  • vite >=2.9.5
packages/playground/package.json
  • typescript ^5.0.0
  • vite ^4.2.0

  • Check this box to trigger a request for Renovate to run again on this repository

Issue With Vite Adapter (Vinxi)

Hello,

I have an error when I try to build (pnpm build) :

Repro : https://github.com/qlaffont/test-solid-thumbhash

Logs :

pnpm build

> example-with-tailwindcss@ build /home/quentin/Documents/dev/test/test-solid-thumbhash
> vinxi build

vinxi v0.3.11


βš™  Building your app...


πŸ“¦ Compiling ssr router...
vinxi building router ssr in http mode
vite v5.2.10 building SSR bundle for production...
βœ“ 48 modules transformed.
.vinxi/build/ssr/assets/test-S2djG7AK.png         1.14 kB
.vinxi/build/ssr/.vite/manifest.json              1.92 kB
.vinxi/build/ssr/assets/test-CAgFW0xs.jpg       329.88 kB
.vinxi/build/ssr/assets/ssr-Hm9xi2M4.css          6.92 kB
.vinxi/build/ssr/index.js                         0.67 kB
.vinxi/build/ssr/_...404_.js                      0.78 kB
.vinxi/build/ssr/assets/components-DhYD1MXP.js    0.82 kB
.vinxi/build/ssr/about.js                         0.99 kB
.vinxi/build/ssr/assets/routing-D05AJeJb.js       7.51 kB
.vinxi/build/ssr/ssr.js                          20.37 kB
βœ“ built in 757ms
βœ” build done                                                                                                                                                            2:31:11 PM


πŸ“¦ Compiling client router...
vinxi building router client in client mode
vite v5.2.10 building for production...
virtual:#vinxi/handler/client (1:118): "default" is not exported by "src/entry-client.tsx", imported by "virtual:#vinxi/handler/client".
βœ“ 53 modules transformed.
x Build failed in 538ms

 ERROR  [vite:asset] Plugin error - Unable to get file name for unknown file "C_p2E6Ly".                                                                                 2:31:11 PM

  at getRollupError (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/parseAst.js:392:41)
  at error (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/parseAst.js:388:42)
  at FileEmitter.getFileName (node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:19131:24)
  at renderAssetUrlInJS (node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-DkOS1hkm.js:15886:26)
  at Object.renderChunk (node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-DkOS1hkm.js:15979:23)
  at node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:19611:40 



 ERROR  [vite:asset] Plugin error - Unable to get file name for unknown file "C_p2E6Ly".                                                                                 2:31:11 PM

 ELIFECYCLE  Command failed with exit code 1.

thanks for your help !

CJS support

Could you build for cjs as well as esm? Shouldn't be too hard to add support for because this plugin already using tsup to build package.

I'm getting following error in my project:

Failed to resolve "vite-plugin-thumbhash". This package is ESM only but it was tried to load by `require`.

I can't switch to esm because of my eslint setup.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.