Skip to content

Commit

Permalink
perf: update non-major deps
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Mar 31, 2024
1 parent 59070ef commit a406215
Show file tree
Hide file tree
Showing 5 changed files with 1,320 additions and 566 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"cSpell.words": ["libvips", "middlewares", "npmrc", "picocolors"],
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"markdownlint.config": {
"no-inline-html": false
}
}
36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
- 🛠 Customize the image type`png`, `jpe?g`, `webp`, `avif`, `heif`, `gif`, `svg`
- 🎉 Flexible path-matching rules
- 🔥 HMR
- 🧱 Support import image module
- 🧱 Support import image module
- 📥 Support for build inline into code(html/css/js)
- 📤 Supports image output to build directory
- 🖥 Develop service injection middleware that supports `GET` requests to get images


## Install

```sh
Expand All @@ -49,8 +48,8 @@ sharp_libvips_binary_host=https://npmmirror.com/mirrors/sharp-libvips

Then reinstall the plugin.


## Usage

```ts
import { defineConfig } from 'vite'
import imagePlaceholder from 'vite-plugin-image-placeholder'
Expand All @@ -77,32 +76,34 @@ In a path to generate placeholder images, the URL consists of `pathname` + `quer
Supports the definition of image background color, text content, text color, width, height, and image type.

- background color: `/background/:background`, or `/bg/:background`

exp: `/background/ccc`, `/bg/fff`, `/bg/255,255,255`

- text content:`/text/:text`, or `/t/:text`

exp: `/text/mark`, `/t/mark`

- text color: `/textColor/:textColor`, or `/color/:textColor` , or `/c/:textColor`
- text color: `/textColor/:textColor`, or `/color/:textColor` , or `/c/:textColor`

exp: `/textColor/999`, `/color/333`, `/c/0,0,0`

- width、height、type: `/:width?/:height?/{.:type}?`

exp: `/300` , `/300/200`, `/300/200.png`, `.png`, `/300.png`

Background color, text content, and text color can be arranged or default,
Background color, text content, and text color can be arranged or default,
which means support for:
```

```txt
/text/:text/bg/:background/textColor/:textColor
/text/:text/textColor/:textColor
/bg/:background/text/:text
/textColor/:textColor
```

Width, height and image format are fixed at the end of `pathname` :
```

```txt
/text/:text/bg/:background/textColor/:textColor/:width?/:height?/{.:type}?
/text/:text/textColor/:textColor/:width?/:height?/{.:type}?
/bg/:background/text/:text/:width?/:height?/{.:type}?
Expand All @@ -118,15 +119,14 @@ Since the `#` in `Hex` conflicts with the `hash` part of the path, the value of

Image type support: `png`, `jpe?g`, `webp`, `avif`, `heif`, `gif`, `svg`


> The plugin strictly checks whether the format of each value of the named parameters meets the requirements. For example, the color value must conform to the format of hex and rgb, and width and height must be integers.
>
>
> If the check fails, the image is not generated, but treated as normal text.

#### query parameters

The query part is not commonly used some image Settings support, currently mainly support image noise.

```ts
interface Query {
noise: 1 | 0 // image noise
Expand All @@ -135,7 +135,7 @@ interface Query {
}
```

# Example
## Example

```txt
/image/placeholder
Expand All @@ -158,27 +158,32 @@ interface Query {
```

In `html`

```html
<img src="/image/placeholder" alt="">
<img src="/image/placeholder/200" alt="">
<img src="/image/placeholder/300/200" alt="">
```

In `css`

```css
.placeholder {
background: url('/image/placeholder');
}
```

In `js` , import modules

```js
import placeholder from 'virtual:image/placeholder'

const img = new Image()
img.src = placeholder
```

In `js`, Inline 'base64' as a string

``` js
const img = new Image()
img.src = '/image/placeholder'
Expand Down Expand Up @@ -296,6 +301,7 @@ export interface OutputFile {
ext: string
}
```

## Archives

[awesome-vite](https://github.com/vitejs/awesome-vite#helpers)
Expand Down
34 changes: 21 additions & 13 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
- 📤 支持打包时图片输出到构建目录
- 🖥 开发服务注入中间件,支持`GET`请求获取图片


## 安装

```sh
Expand All @@ -44,10 +43,11 @@ npm i -D vite-plugin-image-placeholder
sharp_binary_host=https://npmmirror.com/mirrors/sharp
sharp_libvips_binary_host=https://npmmirror.com/mirrors/sharp-libvips
```
然后重新安装插件。

然后重新安装插件。

## 使用

```ts
import { defineConfig } from 'vite'
import imagePlaceholder from 'vite-plugin-image-placeholder'
Expand All @@ -74,30 +74,33 @@ export default defineConfig(() => ({
支持定义图片 背景色、文本内容、文本颜色、宽度、高度、图片格式

- 背景色: `/background/:background`, 或者 `/bg/:background`

exp: `/background/ccc`, `/bg/fff`, `/bg/255,255,255`

- 文本内容:`/text/:text`, 或者 `/t/:text`

exp: `/text/mark`, `/t/mark`

- 文本颜色: `/textColor/:textColor`, 或者 `/color/:textColor` , 或者 `/c/:textColor`
- 文本颜色: `/textColor/:textColor`, 或者 `/color/:textColor` , 或者 `/c/:textColor`

exp: `/textColor/999`, `/color/333`, `/c/0,0,0`

- 宽度、高度、图片格式: `/:width?/:height?/{.:type}?`

exp: `/300` , `/300/200`, `/300/200.png`, `.png`, `/300.png`

其中,背景色,文本内容,文本颜色 三者可以任意排列或缺省,这意味着支持:
```

```txt
/text/:text/bg/:background/textColor/:textColor
/text/:text/textColor/:textColor
/bg/:background/text/:text
/textColor/:textColor
```

宽度、高度、图片格式 三者则固定跟随在 `pathname`的尾部:
```

```txt
/text/:text/bg/:background/textColor/:textColor/:width?/:height?/{.:type}?
/text/:text/textColor/:textColor/:width?/:height?/{.:type}?
/bg/:background/text/:text/:width?/:height?/{.:type}?
Expand All @@ -113,15 +116,14 @@ export default defineConfig(() => ({

图片格式支持: `png`, `jpe?g`, `webp`, `avif`, `heif`, `gif`, `svg`


> 插件会严格校验 named parameters 各个值的格式是否符合要求,比如 颜色值必须符合 hex 和 rgb 的格式, width和height必须是整数。
>
>
> 如果校验不通过,则不会生成图片,而是当做普通文本处理。

#### query 参数

query 部分是不常用的一些图片设置支持,目前主要支持了产生图片噪声。

```ts
interface Query {
noise: 1 | 0 // 图片噪声
Expand All @@ -130,7 +132,7 @@ interface Query {
}
```

# 示例
## 示例

```txt
/image/placeholder
Expand All @@ -153,27 +155,32 @@ interface Query {
```

`html`

```html
<img src="/image/placeholder" alt="">
<img src="/image/placeholder/200" alt="">
<img src="/image/placeholder/300/200" alt="">
```

`css`

```css
.placeholder {
background: url('/image/placeholder');
}
```

`js` 中通过模块导入

```js
import placeholder from 'virtual:image/placeholder'

const img = new Image()
img.src = placeholder
```

`js` 中以字符串的形式内联为 `base64`

``` js
const img = new Image()
img.src = '/image/placeholder'
Expand Down Expand Up @@ -285,6 +292,7 @@ export interface OutputFile {
ext: string
}
```

## Archives

[awesome-vite](https://github.com/vitejs/awesome-vite#helpers)
Expand Down
32 changes: 14 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vite-plugin-image-placeholder",
"type": "module",
"version": "1.0.0",
"packageManager": "pnpm@8.11.0",
"packageManager": "pnpm@8.15.5",
"description": "🔥 Generate a placeholder image for the content area where the image resource is not ready.",
"author": "pengzhanbo <[email protected]> (https://github.com/pengzhanbo)",
"license": "MIT",
Expand All @@ -23,10 +23,6 @@
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
Expand All @@ -37,7 +33,7 @@
"dist"
],
"engines": {
"node": "^16.0.0 || ^18.0.0 || >=20.0.0"
"node": "^18 || >=20.0.0"
},
"scripts": {
"build": "tsup",
Expand All @@ -50,28 +46,28 @@
"release": "bumpp package.json --execute=\"pnpm release:changelog\" --commit --all --push --tag && pnpm publish --access public"
},
"peerDependencies": {
"vite": ">=3.0.0"
"vite": ">=4.0.0"
},
"dependencies": {
"debug": "^4.3.4",
"lru-cache": "^10.1.0",
"magic-string": "^0.30.5",
"lru-cache": "^10.2.0",
"magic-string": "^0.30.8",
"path-to-regexp": "^6.2.1",
"picocolors": "^1.0.0",
"rgb-hex": "^4.1.0",
"sharp": "^0.33.0"
"sharp": "^0.33.3"
},
"devDependencies": {
"@pengzhanbo/eslint-config": "^1.2.4",
"@pengzhanbo/eslint-config": "^1.7.0",
"@types/debug": "^4.1.12",
"@types/node": "^20.10.2",
"@types/node": "^20.12.2",
"@types/sharp": "^0.32.0",
"bumpp": "^9.2.0",
"bumpp": "^9.4.0",
"conventional-changelog-cli": "^4.1.0",
"eslint": "^8.55.0",
"tsup": "^8.0.1",
"typescript": "^5.3.2",
"vite": "^5.0.4",
"vitest": "^0.34.6"
"eslint": "^8.57.0",
"tsup": "^8.0.2",
"typescript": "^5.4.3",
"vite": "^5.2.7",
"vitest": "^1.4.0"
}
}
Loading

0 comments on commit a406215

Please sign in to comment.