The FileManager Webpack Plugin enables comprehensive file management operations during Webpack builds. It provides the ability to copy, move, delete, create directories, and archive files and directories before (onStart) or after (onEnd) the bundling process, with support for glob patterns, parallel/serial execution, and extensive configuration options.
npm install filemanager-webpack-plugin --save-devimport FileManagerPlugin from "filemanager-webpack-plugin";For CommonJS:
const FileManagerPlugin = require("filemanager-webpack-plugin");import FileManagerPlugin from "filemanager-webpack-plugin";
// In webpack.config.js
export default {
plugins: [
new FileManagerPlugin({
events: {
onStart: {
delete: ['./dist'],
mkdir: ['./dist/assets']
},
onEnd: {
copy: [
{ source: './src/assets', destination: './dist/assets' },
{ source: './README.md', destination: './dist/README.md' }
],
archive: [
{ source: './dist', destination: './dist/app.zip' }
]
}
}
})
]
};The FileManager Webpack Plugin is built around several key components:
FileManagerPlugin class that implements Webpack's plugin interfaceonStart and onEnd eventsCore plugin configuration interface and options for controlling execution behavior.
interface FileManagerPluginOptions {
events?: {
onStart?: Actions | Actions[];
onEnd?: Actions | Actions[];
};
runTasksInSeries?: boolean;
runOnceInWatchMode?: boolean;
context?: string | null;
throwOnError?: boolean;
}
interface Actions {
copy?: CopyAction[];
delete?: DeleteAction[];
move?: MoveAction[];
mkdir?: MkdirAction[];
archive?: ArchiveAction[];
}Copy individual files or entire directories with glob pattern support and flexible destination handling.
interface CopyAction {
source: string;
destination: string;
options?: CopyActionOptions;
globOptions?: CopyGlobOptions;
}
interface CopyActionOptions {
flat?: boolean;
overwrite?: boolean;
preserveTimestamps?: boolean;
}Delete individual files or entire directories with support for glob patterns and del package options.
type DeleteAction = string | {
source: string;
options: DeleteOptions;
};Move individual files or entire directories from source to destination locations.
interface MoveAction {
source: string;
destination: string;
}Create directory paths with full recursive support.
type MkdirAction = string;Create archives (zip/tar) from files, directories, or glob patterns with extensive archiver.js options.
interface ArchiveAction {
source: string;
destination: string;
format?: 'zip' | 'tar';
options?: ArchiverOptions;
}/**
* Main FileManager Webpack Plugin class
*/
class FileManagerPlugin {
constructor(options: FileManagerPluginOptions);
apply(compiler: Compiler): void;
}
export default FileManagerPlugin;
export interface FileManagerPluginOptions;