The Trans Directory
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: minify js scripts (closes #655) (#657)

authored by

Jacky Zhao and committed by
GitHub
dafc9f31 e1b6a001

+15 -4
+15 -4
quartz/plugins/emitters/componentResources.ts
··· 14 14 import { QuartzComponent } from "../../components/types" 15 15 import { googleFontHref, joinStyles } from "../../util/theme" 16 16 import { Features, transform } from "lightningcss" 17 + import { transform as transpile } from "esbuild" 17 18 18 19 type ComponentResources = { 19 20 css: string[] ··· 56 57 } 57 58 } 58 59 59 - function joinScripts(scripts: string[]): string { 60 + async function joinScripts(scripts: string[]): Promise<string> { 60 61 // wrap with iife to prevent scope collision 61 - return scripts.map((script) => `(function () {${script}})();`).join("\n") 62 + const script = scripts.map((script) => `(function () {${script}})();`).join("\n") 63 + 64 + // minify with esbuild 65 + const res = await transpile(script, { 66 + minify: true, 67 + }) 68 + 69 + return res.code 62 70 } 63 71 64 72 function addGlobalPageResources( ··· 165 173 addGlobalPageResources(ctx, resources, componentResources) 166 174 167 175 const stylesheet = joinStyles(ctx.cfg.configuration.theme, ...componentResources.css, styles) 168 - const prescript = joinScripts(componentResources.beforeDOMLoaded) 169 - const postscript = joinScripts(componentResources.afterDOMLoaded) 176 + const [prescript, postscript] = await Promise.all([ 177 + joinScripts(componentResources.beforeDOMLoaded), 178 + joinScripts(componentResources.afterDOMLoaded), 179 + ]) 180 + 170 181 const fps = await Promise.all([ 171 182 emit({ 172 183 slug: "index" as FullSlug,