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

@farmfe/plugin-url

A Rust Farm plugin that imports files as data URIs or emitted asset URLs.

Requirements

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

Installation

javascript
npm install -D @farmfe/plugin-url
javascript
yarn add -D @farmfe/plugin-url
javascript
pnpm add -D @farmfe/plugin-url

Usage

Register the plugin in farm.config.ts:

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

export default defineConfig({
  plugins: [
    url({
      limit: 14 * 1024,
    }),
  ],
});

Then import matching assets:

js
import svg from "./image.svg";

console.log(`svg contents: ${svg}`);

Options

  • include?: string[] — regex patterns for files the plugin should process. Defaults to SVG, PNG, JPG/JPEG, GIF, and WebP.
  • exclude?: string[] — regex patterns for files the plugin should ignore.
  • limit?: number — inline files up to this size in bytes. Defaults to 14336 (14 KB). Set 0 to emit all matching files.
  • emitFiles?: boolean — when false, files larger than limit are returned as data URIs instead of being emitted. Defaults to true.

The package types also declare publicPath, filename, sourceDir, and destDir, but the current implementation ignores those fields. Do not include them in user configurations today. Emitted files use Farm's configured output.publicPath and the source file's basename.

100%

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