mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-07-02 02:42:18 -04:00
Added lightning css for minification of css
This commit is contained in:
parent
b376688f75
commit
ee777cdec1
3 changed files with 39 additions and 36 deletions
|
@ -1,33 +0,0 @@
|
|||
'use strict';
|
||||
/**
|
||||
* 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');
|
||||
|
||||
const compressJS = (content) => Terser.minify(content);
|
||||
|
||||
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;
|
||||
} catch (error) {
|
||||
// on error, just yield the un-minified original, but write a log message
|
||||
console.error(`Unexpected error minifying ${filename} (${absPath}): ${error}`);
|
||||
return await fsp.readFile(absPath, 'utf8');
|
||||
}
|
||||
};
|
||||
|
||||
Threads.expose({
|
||||
compressJS,
|
||||
compressCSS,
|
||||
});
|
36
src/node/utils/MinifyWorker.ts
Normal file
36
src/node/utils/MinifyWorker.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
'use strict';
|
||||
/**
|
||||
* Worker thread to minify JS & CSS files out of the main NodeJS thread
|
||||
*/
|
||||
|
||||
import Terser from 'terser'
|
||||
const fsp = require('fs').promises;
|
||||
import path from 'node:path'
|
||||
import Threads from 'threads'
|
||||
import lightminify from 'lightningcss'
|
||||
|
||||
const compressJS = (content: string) => Terser.minify(content);
|
||||
|
||||
const compressCSS = async (filename: string, ROOT_DIR: string) => {
|
||||
const absPath = path.resolve(ROOT_DIR, filename);
|
||||
try {
|
||||
const basePath = path.dirname(absPath);
|
||||
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}): ${JSON.stringify(error)}`);
|
||||
return await fsp.readFile(absPath, 'utf8');
|
||||
}
|
||||
};
|
||||
|
||||
Threads.expose({
|
||||
compressJS,
|
||||
compressCSS,
|
||||
});
|
|
@ -32,7 +32,6 @@
|
|||
"dependencies": {
|
||||
"async": "^3.2.5",
|
||||
"axios": "^1.7.2",
|
||||
"clean-css": "^5.3.3",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"cross-spawn": "^7.0.3",
|
||||
"ejs": "^3.1.10",
|
||||
|
@ -51,9 +50,11 @@
|
|||
"jsonminify": "0.4.2",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"languages4translatewiki": "0.1.3",
|
||||
"lightningcss": "^1.25.1",
|
||||
"live-plugin-manager": "^1.0.0",
|
||||
"lodash.clonedeep": "4.5.0",
|
||||
"log4js": "^6.9.1",
|
||||
"lru-cache": "^10.2.0",
|
||||
"measured-core": "^2.0.0",
|
||||
"mime-types": "^2.1.35",
|
||||
"oidc-provider": "^8.4.5",
|
||||
|
@ -75,8 +76,7 @@
|
|||
"ueberdb2": "^4.2.63",
|
||||
"underscore": "1.13.6",
|
||||
"unorm": "1.6.0",
|
||||
"wtfnode": "^0.9.2",
|
||||
"lru-cache": "^10.2.0"
|
||||
"wtfnode": "^0.9.2"
|
||||
},
|
||||
"bin": {
|
||||
"etherpad-healthcheck": "../bin/etherpad-healthcheck",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue