# rollup-plugin-url

> Inline import files as data-URIs, or copy them to output

Latest version **3.0.1** (published 2019-11-25) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install rollup-plugin-url
pnpm add rollup-plugin-url
yarn add rollup-plugin-url
bun add rollup-plugin-url
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2019-11-25 |
| First published | 2016-02-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/rollup-plugin-url) |
| Module format | CommonJS |
| Node | >=10.0.0 |
| Dependencies | 2 |
| Unpacked size | 14.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 75 |
| Author | Arpad Borsos |
| Maintainers | ashot, swatinem |
| Keywords | rollup-plugin, url, inline, copy |

## Links

- npm: https://www.npmjs.com/package/rollup-plugin-url
- Repository: https://github.com/Swatinem/rollup-plugin-url
- Homepage: https://github.com/Swatinem/rollup-plugin-url#readme
- Issues: https://github.com/Swatinem/rollup-plugin-url/issues
- npm.io page: https://npm.io/package/rollup-plugin-url

## Dependencies (2)

- [mime](https://npm.io/package/mime.md) ^2.4.4
- [rollup-pluginutils](https://npm.io/package/rollup-pluginutils.md) ^2.8.2

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 3.0.1 (latest) — 2019-11-25
- 3.0.0 — 2019-10-08
- 2.2.4 — 2019-10-08
- 2.2.3 — 2019-10-08
- 2.2.2 — 2019-06-13
- 2.2.1 — 2019-04-10
- 2.2.0 — 2019-01-29
- 2.1.0 — 2018-12-02
- 2.0.1 — 2018-10-09
- 2.0.0 — 2018-10-04
- 1.4.0 — 2018-04-17
- 1.3.0 — 2017-09-17
- 1.2.0 — 2017-06-13
- 1.1.0 — 2017-04-11
- 1.0.0 — 2017-04-09
- … 3 more at https://npm.io/package/rollup-plugin-url/versions

## README

# Moved

This module has moved and is now available at [@rollup/plugin-url](https://github.com/rollup/plugins). Please update your dependencies. This repository is no longer maintained.

# rollup-plugin-url

Inline import files as data-URIs, or copy them to output

## Install

```sh
npm i --save-dev rollup-plugin-url
```

## Usage

```js
import {rollup} from "rollup"
import url from "rollup-plugin-url"

const writeoptions = {dest: "output/output.js"}
const plugin = url({
  limit: 10 * 1024, // inline files < 10k, copy files > 10k
  include: ["**/*.svg"], // defaults to .svg, .png, .jpg and .gif files
  emitFiles: true // defaults to true
})

rollup({
  entry: "main.js",
  plugins: [plugin],
})
.then(bundle => bundle.write(writeoptions))
```

## Options

### limit

Optional. Type: `number`.

This is the file size limit to inline files. If files exceed this limit, they
will be copied instead to the destination folder and the hashed filename will
be given instead. If value set to `0` all files will be copied.

Defaults to 14336 (14kb).

### include / exclude

Optional. Type: a minimatch pattern, or array of minimatch patterns

These patterns determine which files are inlined. Defaults to .svg, .png, .jpg
and .gif files.

### publicPath

Optional. Type: `string`

The `publicPath` will be added in front of file names when they are not inlined
but copied.

### emitFiles

Optional. Type: `boolean`

The `emitFiles` option is used to run the plugin as you normally would but prevents any files being emitted. This is useful for when you are using rollup to emit both a client side and server side bundle.

### fileName

Optional. Type: `string`

When `emitFiles` is `true`, the `fileName` option can be used to rename the emitted files. It accepts the following string replacements:

- `[hash]` - The hash value of the file's contents
- `[name]` - The name of the imported file, without it's file extension
- `[extname]` - The extension of the imported file, including the leading `.`
- `[dirname]` - The parent directory name of the imported file, including trailing `/`

Defaults to: `"[hash][extname]"`

### sourceDir

Optional. Type: `string`

When using the `[dirname]` replacement in `fileName`, uses this directory as the source directory to create the file path from rather than the parent directory of the imported file. For example:

*src/path/to/file.js*
```js
import png from "./image.png";
```
*rollup.config.js*
```js
url({
  fileName: "[dirname][hash][extname]",
  sourceDir: path.join(__dirname, "src")
})
```
Emitted File: `path/to/image.png`

### destDir

Optional. Type: `string`

The destination dir to copy assets, usually used to rebase the assets according to HTML files.

---
_Source: https://npm.io/package/rollup-plugin-url · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
