---
title: "@farmfe/plugin-url"
locale: "zh"
version: "current"
canonicalUrl: "https://farmfe.org/zh/docs/plugins/official-plugins/url"
publicationStatus: "prerelease"
---

<a id="farmfeplugin-url"></a>
# @farmfe/plugin-url


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


<a id="requirements"></a>
## Requirements


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


<a id="installation"></a>
## Installation


**npm**

```javascript
npm install -D @farmfe/plugin-url
```


**yarn**

```javascript
yarn add -D @farmfe/plugin-url
```


**pnpm**

```javascript
pnpm add -D @farmfe/plugin-url
```



<a id="usage"></a>
## 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}`);
```


<a id="options"></a>
## 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.
