From 0db5ed7744442220b2e480298f7c02e8d3ee5669 Mon Sep 17 00:00:00 2001 From: Ben Floyd Date: Mon, 5 May 2025 18:14:22 -0600 Subject: [PATCH] minifiy to dist --- .gitignore | 3 ++- esbuild.config.mjs | 27 ++++++++++++++++++++++++++- manifest.json | 21 +++++++++++---------- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index d8a9119..aeeee2a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ main.js *.map data.json .DS_Store -.cursor \ No newline at end of file +.cursor +dist/ \ No newline at end of file diff --git a/esbuild.config.mjs b/esbuild.config.mjs index a5de8b8..e688c06 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -1,6 +1,8 @@ import esbuild from "esbuild"; import process from "process"; import builtins from "builtin-modules"; +import fs from "fs"; +import path from "path"; const banner = `/* @@ -10,6 +12,12 @@ if you want to view the source, please visit the github repository of this plugi `; const prod = (process.argv[2] === "production"); +const distDir = "dist"; + +// Create dist directory if it doesn't exist +if (!fs.existsSync(distDir)) { + fs.mkdirSync(distDir, { recursive: true }); +} const context = await esbuild.context({ banner: { @@ -37,12 +45,29 @@ const context = await esbuild.context({ logLevel: "info", sourcemap: prod ? false : "inline", treeShaking: true, - outfile: "main.js", + outfile: path.join(distDir, "main.js"), minify: prod, }); if (prod) { await context.rebuild(); + + // Minify CSS in production mode + if (fs.existsSync("styles.css")) { + console.log("Minifying CSS..."); + const css = fs.readFileSync("styles.css", "utf8"); + + // Use esbuild's CSS minification + const result = await esbuild.transform(css, { + loader: "css", + minify: true + }); + + // Write to dist directory + fs.writeFileSync(path.join(distDir, "styles.css"), result.code); + console.log("CSS minification complete"); + } + process.exit(0); } else { await context.watch(); diff --git a/manifest.json b/manifest.json index c037cde..1b4ac65 100644 --- a/manifest.json +++ b/manifest.json @@ -1,11 +1,12 @@ { - "id": "streams", - "name": "Streams", - "version": "1.0.0", - "minAppVersion": "0.15.0", - "description": "Create and manage multiple Daily Note streams", - "author": "Ben Floyd", - "authorUrl": "http://floyd.pro", - "fundingUrl": "http://ty.floyd.pro", - "isDesktopOnly": false -} + "id": "streams", + "name": "Streams", + "version": "1.0.0", + "minAppVersion": "0.15.0", + "description": "Create and manage multiple Daily Note streams", + "author": "Floyd", + "authorUrl": "http://floyd.pro", + "fundingUrl": "http://ty.floyd.pro", + "isDesktopOnly": false, + "cssMinified": "dist/styles.css" +} \ No newline at end of file