A Vite plugin to remove/clean your build files or folders before building.
You can install the plugin using npm or yarn:
npm i --save-dev vite-plugin-clean
yarn add --dev vite-plugin-clean
To use the plugin, add it to your Vite configuration file (vite.config.js
or vite.config.ts
). Here's an example:
vite.config.js
import { defineConfig } from 'vite'
import cleanPlugin from 'vite-plugin-clean'
export default defineConfig({
plugins: [
cleanPlugin()
]
})
By default, the plugin will clean the dist
directory before building.
You can customize the plugin's behavior by passing a configuration object. The following options are available:
Name | Type | Default | Description |
---|---|---|---|
targetFiles |
Array<string> | string |
['dist'] |
List of files or directories to be removed before the build process starts. |
vite.config.js
import { defineConfig } from 'vite'
import cleanPlugin from 'vite-plugin-clean'
export default defineConfig({
plugins: [
cleanPlugin({
targetFiles: ['dist', 'test'] // Clean both 'dist' and 'test' directories
})
]
})
Or, if you want to clean specific files:
vite.config.js
import { defineConfig } from 'vite'
import cleanPlugin from 'vite-plugin-clean'
export default defineConfig({
plugins: [
cleanPlugin({
targetFiles: ['bak.zip', 'test.js', 'demo.html'] // Clean specific files
})
]
})
- Vite Version Compatibility: This plugin is designed to work with the latest versions of Vite. Ensure you are using a recent version of Vite to avoid compatibility issues. If you encounter any problems, consider updating Vite to the latest version.
- File Deletion: Be cautious when specifying files or directories in the
targetFiles
option. The plugin will permanently delete the specified files or folders before the build process.
If you encounter any issues or have suggestions for improvements, please click here Issue Report
Copyright (c) 2022-present flyfox