跳到主要内容
FarmFarm
Version: 2.x(最新)
本页目录

@farmfe/plugin-image

A Rust Farm plugin that imports JPG, PNG, GIF, SVG, and WebP files as base64 data URIs.

Requirements

This plugin requires Node.js v18.0.0+ and Farm v1.0.0+.

Installation

javascript
npm install @farmfe/plugin-image
javascript
yarn add @farmfe/plugin-image
javascript
pnpm add @farmfe/plugin-image

Usage

Register the plugin in farm.config.ts:

ts
import { defineConfig } from "@farmfe/core";
import image from "@farmfe/plugin-image";

export default defineConfig({
  plugins: [image()],
});

Then import images from application code:

js
import logo from "./logo.png";

console.log(logo);

Options

  • dom?: boolean — when true, export a DOM Image element instead of a base64 string. Defaults to false.
  • include?: string[] — regex patterns for files the plugin should process.
  • exclude?: string[] — regex patterns for files the plugin should ignore.

With dom: true, the imported value can be appended directly to the document:

js
import logo from "./logo.png";

document.body.appendChild(logo);
100%

Drag or pinch to explore. Keyboard: + / − zoom, arrows pan, 0 resets, Esc closes.