mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-21 10:01:18 -04:00
add a *very* basic minifier to remove the insane amount of whitespace from compiled MDX
This commit is contained in:
25
lib/helpers/minifier.ts
Normal file
25
lib/helpers/minifier.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { trimLines } from "trim-lines";
|
||||
import stripComments from "strip-comments";
|
||||
|
||||
// do some _very_ rudimentary JS minifying.
|
||||
export const minifier = (source: string): string => {
|
||||
// save the first line for later, it might be important?
|
||||
const firstLine = source.split("\n")[0];
|
||||
|
||||
// remove JS comments
|
||||
source = stripComments(source, {
|
||||
block: false,
|
||||
keepProtected: true,
|
||||
});
|
||||
// remove indentation
|
||||
source = trimLines(source);
|
||||
// remove newlines
|
||||
source = source.replace(/\n/g, "");
|
||||
|
||||
// restore JSX flags if they were there at the beginning
|
||||
if (firstLine.startsWith("/*@jsx")) {
|
||||
source = `${firstLine}${source}`;
|
||||
}
|
||||
|
||||
return source;
|
||||
};
|
Reference in New Issue
Block a user