This repository has been archived on 2025-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
coryd.dev-eleventy/config/events/index.js

16 lines
532 B
JavaScript

import fs from 'fs'
import { minify } from 'terser'
export const minifyJsComponents = async () => {
const jsComponentsDir = '_site/assets/scripts/components';
const files = fs.readdirSync(jsComponentsDir);
for (const fileName of files) {
if (fileName.endsWith('.js')) {
const filePath = `${jsComponentsDir}/${fileName}`;
const minified = await minify(fs.readFileSync(filePath, 'utf8'));
fs.writeFileSync(filePath, minified.code);
} else {
console.log('⚠ No js components found')
}
}
}