mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 00:16:15 -04:00
Feat/lightningcss (#6427)
* Added lightning css for minification of css * Added esbuild for minification * Upgraded to Node 22 * Fixed. * Temporary change branch * Rebased changes.
This commit is contained in:
parent
b376688f75
commit
426174d491
8 changed files with 5329 additions and 3946 deletions
|
@ -3,31 +3,45 @@
|
|||
* Worker thread to minify JS & CSS files out of the main NodeJS thread
|
||||
*/
|
||||
|
||||
const CleanCSS = require('clean-css');
|
||||
const Terser = require('terser');
|
||||
const fsp = require('fs').promises;
|
||||
const path = require('path');
|
||||
const Threads = require('threads');
|
||||
import path from 'node:path'
|
||||
import {expose} from 'threads'
|
||||
import lightminify from 'lightningcss'
|
||||
import {transform} from 'esbuild';
|
||||
|
||||
const compressJS = (content) => Terser.minify(content);
|
||||
/*
|
||||
* Minify JS content
|
||||
* @param {string} content - JS content to minify
|
||||
*/
|
||||
const compressJS = async (content) => {
|
||||
return await transform(content, {minify: true});
|
||||
}
|
||||
|
||||
/*
|
||||
* Minify CSS content
|
||||
* @param {string} filename - name of the file
|
||||
* @param {string} ROOT_DIR - the root dir of Etherpad
|
||||
*/
|
||||
const compressCSS = async (filename, ROOT_DIR) => {
|
||||
const absPath = path.resolve(ROOT_DIR, filename);
|
||||
try {
|
||||
const basePath = path.dirname(absPath);
|
||||
const output = await new CleanCSS({
|
||||
rebase: true,
|
||||
rebaseTo: basePath,
|
||||
}).minify([absPath]);
|
||||
return output.styles;
|
||||
const file = await fsp.readFile(absPath, 'utf8');
|
||||
let { code } = lightminify.transform({
|
||||
errorRecovery: true,
|
||||
filename: basePath,
|
||||
minify: true,
|
||||
code: Buffer.from(file, 'utf8')
|
||||
});
|
||||
return code.toString();
|
||||
} catch (error) {
|
||||
// on error, just yield the un-minified original, but write a log message
|
||||
console.error(`Unexpected error minifying ${filename} (${absPath}): ${error}`);
|
||||
console.error(`Unexpected error minifying ${filename} (${absPath}): ${JSON.stringify(error)}`);
|
||||
return await fsp.readFile(absPath, 'utf8');
|
||||
}
|
||||
};
|
||||
|
||||
Threads.expose({
|
||||
compressJS,
|
||||
expose({
|
||||
compressJS: compressJS,
|
||||
compressCSS,
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue