mirror-cockpit-project-cockpit/pkg/lib/esbuild-cleanup-plugin.js
Allison Karlitskaya af3ec756f5 pkg/lib, build.js: DRY on 'dist/'
Stop hardcoding 'dist/' all over the place.  We already do it once in
the esbuild configuration blob, and that's enough.  The other places
(and particularly the plugins) should be reading it from there.

For the qunit plugin, remove a hardcoded instance of 'qunit/'.
2026-11-03 10:46:22 +01:00

18 lines
599 B
JavaScript

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