Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rollup-plugin-url

Swatinem61.6kMITdeprecated3.0.1TypeScript support: definitely-typed

This module has been deprecated and is no longer maintained. Please use @rollup/plugin-url.

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

rollup-plugin, url, inline, copy

readme

Moved

This module has moved and is now available at @rollup/plugin-url. 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

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

Usage

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

import png from "./image.png";

rollup.config.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.

changelog

Changelog

3.0.0 / 2019-10-08

  • drop node 8 support as it's maintenance will be closed in December
  • migrate to MIT License

2.2.4 / 2019-10-08

  • fallback to mkdirp to keep working on node <= 8

2.2.3 / 2019-10-08

  • remove mkpath from dependencies (#24)
  • update dev dependencies

2.2.2 / 2019-06-13

  • dependencies update

2.2.1 / 2019-04-10

  • Fix dirname substitution on Windows (#21)

2.2.0 / 2019-01-29

  • add destDir option (#19)
  • update dependencies

2.1.0 / 2018-12-02

  • add fileName option (#17)

2.0.1 / 2018-10-09

  • ensure destination folder exist while generateBundle hook performs

2.0.0 / 2018-10-01

  • Breaking: version 2.0.0 requires rollup@0.60 and higher – deprecated onwrite hook replaced with new generateBundle hook, so plugin will not work with earlier versions of rollup.
    Use version 1.4 with rollup<0.60

1.4.0 / 2018-04-17

  • add support for output.dir option
  • update dependencies

1.3.0 / 2017-09-17

1.2.0 / 2017-06-09

  • add ability to prevent emitting any files with the emitFiles=false option.

1.1.0 / 2017-04-12

  • set default limit to 14kb

1.0.0 / 2017-04-10

  • Migrate to newer rollup API (#5).
  • Minimal rollup version is 0.32.4
  • Braking: write method was removed

0.1.2 / 2016-08-30

  • Add public path option (#1)

0.1.1 / 2016-02-08

  • drop charset, its not needed

0.1.0 / 2016-02-08

  • Initial release