🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

mika-vite-img2base64-plugin

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mika-vite-img2base64-plugin

#### 插件功能 - **自动转换**:将 PNG、JPG/JPEG、WebP 格式的图片自动转换为 Base64 数据 URL - **大小限制**:默认只转换小于 100KB 的图片,超过限制的图片保持原样 - **配置灵活**:可以通过参数调整转换大小限制

latest
Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
4
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

mika-img2base64-plugin

插件功能

  • 自动转换:将 PNG、JPG/JPEG、WebP 格式的图片自动转换为 Base64 数据 URL
  • 大小限制:默认只转换小于 100KB 的图片,超过限制的图片保持原样
  • 配置灵活:可以通过参数调整转换大小限制

使用方法

  • vite.config.js 中导入并配置插件:
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import mikaImg2Base64Plugin from 'mika-img2base64-plugin'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    mikaImg2Base64Plugin(100000) // 参数为转换大小限制(字节)
  ],
})
  • 在代码中正常导入图片:
import logo from './assets/logo.png'

当图片大小小于设定的限制时,插件会自动将其转换为 Base64 格式,无需修改任何导入代码。

插件工作原理

插件通过 Vite 的 transform 钩子函数,在构建过程中:

  • 检测导入的图片文件
  • 检查图片大小是否超过设定限制
  • 将符合条件的图片转换为 Base64 数据 URL
  • 返回转换后的代码,替换原始导入
image

FAQs

Package last updated on 02 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts