You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
966 B

// @ts-nocheck
const fs = require('fs');
const path = require('path');
class DeleteCssPlugin {
constructor(options) {
this.options = options || {};
}
apply(compiler) {
compiler.hooks.done.tap('DeleteCssPlugin', (stats) => {
const outputPath =
this.options.outputPath || path.resolve(__dirname, 'dist');
fs.readdir(outputPath, (err, files) => {
if (err) {
console.error(`Failed to read directory: ${outputPath}`, err);
return;
}
files.forEach((file) => {
if (file.endsWith('.css')) {
const filePath = path.join(outputPath, file);
fs.unlink(filePath, (err) => {
if (err) {
console.error(`Failed to delete file: ${filePath}`, err);
} else {
console.log(`Deleted: ${filePath}`);
}
});
}
});
});
});
}
}
module.exports = DeleteCssPlugin;