gregnb / filemanager-webpack-plugin

Copy, move, archive (zip/tar/tar.gz), delete files and directories before and after Webpack builds. Win32/Mac/*Nix supported
MIT License
463 stars 34 forks source link

Remove empty dirs (recursively) #125

Open Andrew15-5 opened 1 year ago

Andrew15-5 commented 1 year ago

Config

const path = require('path');
const FilemanagerWebpackPlugin = require('filemanager-webpack-plugin');

const output_dir = path.resolve('public');
const js_dir = path.join(output_dir, 'js');

const config = {
  output: {
    path: output_dir,
  },
  plugins: [
    new FilemanagerWebpackPlugin({
      events: {
        onEnd: {
          delete: [path.join(js_dir, '**', '*.d.ts')],
        },
      },
    }),
  ],
};

Issue

I have ts-loader that is used instead of tsc, therefore I can't remove .d.ts. I was able to achieve it with this plugin, but now I have empty dirs. I was wondering if I can do something like:

delete: [
  {
    source: 'dir/**',
    options: {
      'only-empty-dirs': true,
    },
  },
],

I want it to be able to recursively (because of ** ) remove all empty dirs (starting from the bottom or with smart check).

I don't know how to change the config syntax, but I would also like to remove the top source dir itself too, if everything inside it is only empty dirs.

Your Environment

Tech Version
filemanager-plugin-webpack 8.0.0
node v18.16.0
OS Pop!_OS 22.04