@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-imagejavascript
yarn add @farmfe/plugin-imagejavascript
pnpm add @farmfe/plugin-imageUsage
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— whentrue, export a DOMImageelement instead of a base64 string. Defaults tofalse.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);
Farm