etherpad-lite/src/node/utils/MinifyWorker.ts
SamTV12345 c7a2dea4d1
Feat/frontend vitest (#6469)
* Added vitest tests.

* Added Settings tests to vitest - not working

* Added attributes and attributemap to vitest.

* Added more tests.

* Also run the vitest tests.

* Also run withoutPlugins

* Fixed pnpm lock
2024-08-16 22:55:42 +02:00

42 lines
976 B
TypeScript

'use strict';
/**
* Worker thread to minify JS & CSS files out of the main NodeJS thread
*/
import {build, transform} from 'esbuild';
/*
* Minify JS content
* @param {string} content - JS content to minify
*/
export const compressJS = async (content: string) => {
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
*/
export const compressCSS = async (content: string) => {
const transformedCSS = await build(
{
entryPoints: [content],
minify: true,
bundle: true,
loader:{
'.jpg': 'dataurl',
'.png': 'dataurl',
'.gif': 'dataurl',
'.ttf': 'dataurl',
'.otf': 'dataurl',
'.woff': 'dataurl',
'.woff2': 'dataurl',
'.eot': 'dataurl',
'.svg': 'dataurl'
},
write: false
}
)
return transformedCSS.outputFiles[0].text
};