@visulima/packem
Version:
A fast and modern bundler for Node.js and TypeScript.
73 lines (72 loc) • 2.8 kB
text/typescript
import type { FilterPattern } from "@rollup/pluginutils";
import type { Plugin } from "rollup";
export interface UrlOptions {
/**
* The destination dir to copy assets, usually used to rebase the assets according to HTML files.
* @type {string}
*/
destDir?: string;
/**
* If false, will prevent files being emitted by this plugin. This is useful for when you are using Rollup to emit both a client-side and server-side bundle.
* @type {boolean}
* @default true
*/
emitFiles: boolean;
/**
* A picomatch pattern, or array of patterns, which specifies the files in the build the plugin
* should _ignore_.
*
* By default, no files are ignored.
* @type {FilterPattern}
*/
exclude?: FilterPattern;
/**
* If emitFiles is true, this 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 its file extension)
* [extname] - The extension of the imported file (including the leading .)
* [dirname] - The parent directory name of the imported file (including trailing /)
* @type {string}
* @default [hash][extname]
*/
fileName: string;
/**
* A picomatch pattern, or array of patterns, which specifies the files in the build the plugin
* should operate on.
* By default, the png,jpg,jpeg,gif,svg,webp files are targeted.
* @type {FilterPattern}
*/
include?: FilterPattern;
/**
* The file size limit for inline files.
* If a file exceeds this limit, it will be copied to the destination folder and the hashed filename will be provided instead.
* If limit is set to 0 all files will be copied.
* @type {number}
* @default 14336 (14kb)
*/
limit: number;
/**
* A string which will be added in front of filenames when they are not inlined but are copied.
* @type {string}
*/
publicPath?: string;
/**
* When using the [dirname] replacement in fileName, use this directory as the source directory from which to create the file path rather than the parent directory of the imported file. For example:
* @example
* ```js
* src/path/to/file.js
*
* import png from './image.d.cts';
* rollup.config.js
*
* url({
* fileName: '[dirname][hash][extname]',
* sourceDir: path.join(__dirname, 'src')
* });
*
* Emitted File: path/to/image.png
* ```
*/
sourceDir?: string;
}
export declare const urlPlugin: ({ destDir: destinationDirectory, emitFiles, exclude, fileName, include, limit, publicPath, sourceDir: sourceDirectory, }: UrlOptions) => Plugin;