Debian Codegraph @

pkg/lib/esbuild-cleanup-plugin.js

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 import fs from 'node:fs';
3 import path from 'node:path';
4
5 // always start with a fresh dist/ directory, to change between development and production, or clean up gzipped files
6 export const cleanPlugin = ({ outdir = './dist', subdir = '' } = {}) => ({
7 name: 'clean-dist',
8 setup(build) {
9 build.onStart(() => {
10 try {
11 fs.rmSync(path.resolve(outdir, subdir), { recursive: true });
12 } catch (e) {
13 if (e.code !== 'ENOENT')
14 throw e;
15 }
16 });
17 }
18 });