forked from ppfun/pixelplanet
do minifyCss right after cleaning assets
Use hashes in css filenames again
This commit is contained in:
parent
0a4199e633
commit
058290aa16
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { spawn } = require('node:child_process');
|
const { spawn } = require('child_process');
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
|
|
||||||
const minifyCss = require('./minifyCss');
|
const minifyCss = require('./minifyCss');
|
||||||
|
@ -165,7 +165,7 @@ async function buildProduction() {
|
||||||
|
|
||||||
if (!recursion) {
|
if (!recursion) {
|
||||||
console.log(
|
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({
|
await compile(clientConfig({
|
||||||
development: false,
|
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 (doBuildClient) {
|
||||||
if (parallel) {
|
if (parallel) {
|
||||||
promises.push(buildClientsParallel(avlangs));
|
promises.push(buildClientsParallel(avlangs));
|
||||||
|
@ -187,7 +194,6 @@ async function buildProduction() {
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
|
||||||
if (!recursion) {
|
if (!recursion) {
|
||||||
await minifyCss();
|
|
||||||
console.log(`Finished building in ${(Date.now() - st) / 1000}s`);
|
console.log(`Finished building in ${(Date.now() - st) / 1000}s`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Worker done in ${(Date.now() - st) / 1000}s`);
|
console.log(`Worker done in ${(Date.now() - st) / 1000}s`);
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const CleanCSS = require('clean-css');
|
const CleanCSS = require('clean-css');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
const buildTs = Date.now();
|
const buildTs = Date.now();
|
||||||
const assetdir = path.resolve(__dirname, '..', 'dist', 'public', 'assets');
|
const assetdir = path.resolve(__dirname, '..', 'dist', 'public', 'assets');
|
||||||
|
@ -40,11 +41,12 @@ async function minifyCss() {
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
console.log('\x1b[33m%s\x1b[0m', `Minified ${file} by ${Math.round(output.stats.efficiency * 100)}%`);
|
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('.'));
|
let key = file.substr(0, file.indexOf('.'));
|
||||||
if (key.startsWith('theme-')) {
|
if (key.startsWith('theme-')) {
|
||||||
key = key.substr(6);
|
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');
|
fs.writeFileSync(path.resolve(assetdir, filename), output.styles, 'utf8');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user