do minifyCss right after cleaning assets

Use hashes in css filenames again
This commit is contained in:
HF 2023-12-13 11:10:07 +01:00
parent 0a4199e633
commit 058290aa16
2 changed files with 12 additions and 4 deletions

View File

@ -5,7 +5,7 @@
const path = require('path');
const fs = require('fs');
const { spawn } = require('node:child_process');
const { spawn } = require('child_process');
const webpack = require('webpack');
const minifyCss = require('./minifyCss');
@ -165,7 +165,7 @@ async function buildProduction() {
if (!recursion) {
console.log(
'Building one package seperately to populate cache and extract langs...',
'Building one package seperately to populate cache and possibly extract langs...',
);
await compile(clientConfig({
development: false,
@ -177,6 +177,13 @@ async function buildProduction() {
}));
}
if (!recursion) {
console.log('-----------------------------');
console.log(`Minify CSS assets...`);
console.log('-----------------------------');
await minifyCss();
}
if (doBuildClient) {
if (parallel) {
promises.push(buildClientsParallel(avlangs));
@ -187,7 +194,6 @@ async function buildProduction() {
await Promise.all(promises);
if (!recursion) {
await minifyCss();
console.log(`Finished building in ${(Date.now() - st) / 1000}s`);
} else {
console.log(`Worker done in ${(Date.now() - st) / 1000}s`);

View File

@ -12,6 +12,7 @@
const fs = require('fs');
const path = require('path');
const CleanCSS = require('clean-css');
const crypto = require('crypto');
const buildTs = Date.now();
const assetdir = path.resolve(__dirname, '..', 'dist', 'public', 'assets');
@ -40,11 +41,12 @@ async function minifyCss() {
}
// eslint-disable-next-line max-len
console.log('\x1b[33m%s\x1b[0m', `Minified ${file} by ${Math.round(output.stats.efficiency * 100)}%`);
const hash = crypto.createHash('md5').update(output.styles).digest('hex');
let key = file.substr(0, file.indexOf('.'));
if (key.startsWith('theme-')) {
key = key.substr(6);
}
const filename = `${key}.${buildTs}.css`;
const filename = `${key}.${hash.substr(0, 8)}.css`;
fs.writeFileSync(path.resolve(assetdir, filename), output.styles, 'utf8');
});
}