or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.md

index.mddocs/

0

# Rollup Plugin Delete

1

2

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.

3

4

## Package Information

5

6

- **Package Name**: rollup-plugin-delete

7

- **Package Type**: npm

8

- **Language**: TypeScript

9

- **Installation**: `npm install rollup-plugin-delete -D`

10

- **Repository**: https://github.com/vladshcherbin/rollup-plugin-delete

11

12

## Core Imports

13

14

```typescript

15

import del from "rollup-plugin-delete";

16

// Named export also available for types

17

import { type Options } from "rollup-plugin-delete";

18

```

19

20

For CommonJS:

21

22

```javascript

23

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

24

```

25

26

## Basic Usage

27

28

```typescript

29

import del from "rollup-plugin-delete";

30

31

export default {

32

input: "src/index.js",

33

output: {

34

file: "dist/app.js"

35

},

36

plugins: [

37

del({ targets: "dist" })

38

]

39

};

40

```

41

42

## Architecture

43

44

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

45

46

- **Plugin Factory Function**: Creates a Rollup plugin instance with deletion capabilities

47

- **Hook Integration**: Supports execution on any Rollup async hook (default: `buildStart`)

48

- **Pattern Matching**: Uses glob patterns for file/folder targeting via the `del` package

49

- **Watch Mode Support**: Includes `runOnce` option for watch scenarios to prevent repeated deletions

50

51

## Capabilities

52

53

This package exports:

54

- **Default export**: `del` function - the main plugin factory

55

- **Named export**: `Options` interface - TypeScript type for configuration

56

57

### Plugin Factory Function (Default Export)

58

59

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

60

61

```typescript { .api }

62

/**

63

* Creates a Rollup plugin for deleting files and folders

64

* @param options - Configuration options for the deletion plugin

65

* @returns Rollup Plugin object with name 'delete'

66

*/

67

function del(options?: Options): Plugin;

68

```

69

70

**Usage Examples:**

71

72

```typescript

73

// Delete entire directory

74

del({ targets: "dist" })

75

76

// Delete specific files

77

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

78

79

// Delete multiple patterns

80

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

81

82

// Use with verbose logging

83

del({

84

targets: "dist/*",

85

verbose: true

86

})

87

88

// Run on different hook

89

del({

90

targets: "dist",

91

hook: "buildEnd"

92

})

93

94

// Watch mode optimization

95

del({

96

targets: "dist",

97

runOnce: true

98

})

99

```

100

101

### Options Interface (Named Export)

102

103

Configuration interface extending all options from the `del` package.

104

105

```typescript { .api }

106

interface Options extends DelOptions {

107

/**

108

* Rollup hook the plugin should use.

109

* @default 'buildStart'

110

*/

111

readonly hook?: AsyncPluginHooks;

112

113

/**

114

* Delete items once. Useful in watch mode.

115

* @default false

116

*/

117

readonly runOnce?: boolean;

118

119

/**

120

* Patterns of files and folders to be deleted.

121

* @default []

122

*/

123

readonly targets?: readonly string[] | string;

124

125

/**

126

* Outputs removed files and folders to console.

127

* @default false

128

*/

129

readonly verbose?: boolean;

130

}

131

```

132

133

### Hook Options

134

135

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

136

137

```typescript { .api }

138

// Imported from 'rollup' package

139

type AsyncPluginHooks =

140

| "buildStart"

141

| "buildEnd"

142

| "generateBundle"

143

| "writeBundle"

144

| "closeBundle"

145

| "renderStart"

146

| "renderError"

147

| "resolveDynamicImport"

148

| "resolveId"

149

| "load"

150

| "transform"

151

| "moduleParsed"

152

| "onLog";

153

```

154

155

## Types

156

157

### Core Types

158

159

The plugin uses types imported from external packages:

160

161

```typescript { .api }

162

// From 'rollup' package

163

interface Plugin {

164

name: string;

165

[hookName: string]: any;

166

}

167

168

// From 'del' package

169

interface DelOptions {

170

// Defined below

171

}

172

```

173

174

### Inherited Del Package Options

175

176

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

177

178

```typescript { .api }

179

interface DelOptions {

180

/**

181

* See what would be deleted without actually deleting

182

* @default false

183

*/

184

readonly dryRun?: boolean;

185

186

/**

187

* Number of concurrent deletions

188

* @default Infinity

189

*/

190

readonly concurrency?: number;

191

192

/**

193

* Called for each file/directory before deletion

194

*/

195

readonly onProgress?: (progress: {

196

totalCount: number;

197

deletedCount: number;

198

percent: number;

199

}) => void;

200

201

/**

202

* Patterns to ignore

203

* @default []

204

*/

205

readonly ignore?: readonly string[];

206

207

/**

208

* Allow deleting files/directories outside current working directory

209

* @default false

210

*/

211

readonly force?: boolean;

212

213

/**

214

* Allow deleting non-empty directories

215

* @default true

216

*/

217

readonly onlyFiles?: boolean;

218

}

219

```

220

221

## Error Handling

222

223

The plugin will throw errors in the following scenarios:

224

- Invalid glob patterns in `targets`

225

- Permission errors when deleting files/directories

226

- File system errors during deletion operations

227

228

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

229

230

## Pattern Examples

231

232

Common glob patterns for targeting files and folders:

233

234

```typescript

235

// Single folder

236

{ targets: "dist" }

237

238

// Single file

239

{ targets: "dist/app.js" }

240

241

// All JS files in folder

242

{ targets: "dist/*.js" }

243

244

// All files in folder and subfolders

245

{ targets: "dist/**/*" }

246

247

// Multiple patterns

248

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

249

250

// Exclude specific files

251

{

252

targets: "dist/*",

253

ignore: ["dist/important.js"]

254

}

255

```