summaryrefslogtreecommitdiffstats
path: root/pkg/lib/esbuild-cleanup-plugin.js
blob: a3a7555dcc41d2b6f6cca1aedaa0ef809f0adbac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import fs from 'fs';
import path from 'path';

// always start with a fresh dist/ directory, to change between development and production, or clean up gzipped files
export const cleanPlugin = ({ outdir = './dist', subdir = '' } = {}) => ({
    name: 'clean-dist',
    setup(build) {
        build.onStart(() => {
            try {
                fs.rmSync(path.resolve(outdir, subdir), { recursive: true });
            } catch (e) {
                if (e.code !== 'ENOENT')
                    throw e;
            }
        });
    }
});