or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-rollup-plugin-delete

Delete files and folders using Rollup

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/rollup-plugin-delete@3.0.x

To install, run

npx @tessl/cli install tessl/npm-rollup-plugin-delete@3.0.0

index.mddocs/

Rollup Plugin Delete

Rollup Plugin Delete provides a Rollup plugin for deleting files and folders during the build process. It offers a simple but flexible API for cleaning dist directories, removing generated files, and maintaining clean build environments.

Package Information

  • Package Name: rollup-plugin-delete
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install rollup-plugin-delete -D
  • Repository: https://github.com/vladshcherbin/rollup-plugin-delete

Core Imports

import del from "rollup-plugin-delete";
// Named export also available for types
import { type Options } from "rollup-plugin-delete";

For CommonJS:

const del = require("rollup-plugin-delete");

Basic Usage

import del from "rollup-plugin-delete";

export default {
  input: "src/index.js",
  output: {
    file: "dist/app.js"
  },
  plugins: [
    del({ targets: "dist" })
  ]
};

Architecture

The plugin integrates with Rollup's hook system and leverages the robust del package internally for reliable file deletion operations. Key components:

  • Plugin Factory Function: Creates a Rollup plugin instance with deletion capabilities
  • Hook Integration: Supports execution on any Rollup async hook (default: buildStart)
  • Pattern Matching: Uses glob patterns for file/folder targeting via the del package
  • Watch Mode Support: Includes runOnce option for watch scenarios to prevent repeated deletions

Capabilities

This package exports:

  • Default export: del function - the main plugin factory
  • Named export: Options interface - TypeScript type for configuration

Plugin Factory Function (Default Export)

Creates a Rollup plugin that deletes files and folders during the build process.

/**
 * Creates a Rollup plugin for deleting files and folders
 * @param options - Configuration options for the deletion plugin
 * @returns Rollup Plugin object with name 'delete'
 */
function del(options?: Options): Plugin;

Usage Examples:

// Delete entire directory
del({ targets: "dist" })

// Delete specific files
del({ targets: "dist/*.js" })

// Delete multiple patterns
del({ targets: ["dist/*", "images/*.webp"] })

// Use with verbose logging
del({ 
  targets: "dist/*",
  verbose: true
})

// Run on different hook
del({ 
  targets: "dist",
  hook: "buildEnd"
})

// Watch mode optimization
del({ 
  targets: "dist",
  runOnce: true
})

Options Interface (Named Export)

Configuration interface extending all options from the del package.

interface Options extends DelOptions {
  /**
   * Rollup hook the plugin should use.
   * @default 'buildStart'
   */
  readonly hook?: AsyncPluginHooks;

  /**
   * Delete items once. Useful in watch mode.
   * @default false
   */
  readonly runOnce?: boolean;

  /**
   * Patterns of files and folders to be deleted.
   * @default []
   */
  readonly targets?: readonly string[] | string;

  /**
   * Outputs removed files and folders to console.
   * @default false
   */
  readonly verbose?: boolean;
}

Hook Options

The plugin supports any async hook defined by Rollup's AsyncPluginHooks type:

// Imported from 'rollup' package
type AsyncPluginHooks = 
  | "buildStart"
  | "buildEnd" 
  | "generateBundle"
  | "writeBundle"
  | "closeBundle"
  | "renderStart"
  | "renderError"
  | "resolveDynamicImport"
  | "resolveId"
  | "load"
  | "transform"
  | "moduleParsed"
  | "onLog";

Types

Core Types

The plugin uses types imported from external packages:

// From 'rollup' package
interface Plugin {
  name: string;
  [hookName: string]: any;
}

// From 'del' package  
interface DelOptions {
  // Defined below
}

Inherited Del Package Options

The plugin inherits all options from the del package for advanced file deletion patterns:

interface DelOptions {
  /**
   * See what would be deleted without actually deleting
   * @default false
   */
  readonly dryRun?: boolean;

  /**
   * Number of concurrent deletions
   * @default Infinity
   */
  readonly concurrency?: number;

  /**
   * Called for each file/directory before deletion
   */
  readonly onProgress?: (progress: {
    totalCount: number;
    deletedCount: number;
    percent: number;
  }) => void;

  /**
   * Patterns to ignore
   * @default []
   */
  readonly ignore?: readonly string[];

  /**
   * Allow deleting files/directories outside current working directory
   * @default false
   */
  readonly force?: boolean;

  /**
   * Allow deleting non-empty directories
   * @default true
   */
  readonly onlyFiles?: boolean;
}

Error Handling

The plugin will throw errors in the following scenarios:

  • Invalid glob patterns in targets
  • Permission errors when deleting files/directories
  • File system errors during deletion operations

When using dryRun: true, no actual deletion occurs, but the plugin will still validate patterns and log what would be deleted.

Pattern Examples

Common glob patterns for targeting files and folders:

// Single folder
{ targets: "dist" }

// Single file
{ targets: "dist/app.js" }

// All JS files in folder
{ targets: "dist/*.js" }

// All files in folder and subfolders
{ targets: "dist/**/*" }

// Multiple patterns
{ targets: ["dist/*", "temp/**/*", "*.log"] }

// Exclude specific files
{ 
  targets: "dist/*",
  ignore: ["dist/important.js"]
}