Add separate manifest for dev builds and suppress svelte warnings

This commit is contained in:
Evan Fiordeliso 2025-07-01 11:28:35 -04:00
parent e64e28cbe3
commit 8c94599a31
4 changed files with 32 additions and 12 deletions

View File

@ -5,9 +5,11 @@ import esbuildSvelte from "esbuild-svelte";
import { sveltePreprocess } from "svelte-preprocess"; import { sveltePreprocess } from "svelte-preprocess";
import dotenv from "dotenv"; import dotenv from "dotenv";
import dotenvExpand from "dotenv-expand"; import dotenvExpand from "dotenv-expand";
import manifest from "./manifest.json" with { type: "json" }; import fs from "fs";
import fs from "fs/promises";
import path from "path"; import path from "path";
import { execSync } from "child_process";
const manifest = JSON.parse(fs.readFileSync("manifest.json", "utf8"));
const env = dotenv.config(); const env = dotenv.config();
dotenvExpand.expand(env); dotenvExpand.expand(env);
@ -35,6 +37,14 @@ if (outDir[0] === "~") {
outDir = path.join(process.env.HOME, outDir.slice(1)); outDir = path.join(process.env.HOME, outDir.slice(1));
} }
const commitHash = execSync("git rev-parse --short HEAD");
const devManifest = {
...manifest,
id: `${manifest.id}-dev`,
name: `${manifest.name} (Dev)`,
version: `dev-${commitHash}`,
};
const context = await esbuild.context({ const context = await esbuild.context({
banner: { banner: {
js: banner, js: banner,
@ -47,29 +57,37 @@ const context = await esbuild.context({
compilerOptions: { dev: !prod }, compilerOptions: { dev: !prod },
}), }),
{ {
name: 'copy-plugin', name: "copy-plugin",
setup(build) { setup(build) {
build.onEnd(async () => { build.onEnd(() => {
try { try {
await fs.copyFile(new URL('./manifest.json', import.meta.url), path.resolve(outDir, 'manifest.json')); console.log("Writing manifest.json");
fs.writeFileSync(
path.resolve(outDir, "manifest.json"),
JSON.stringify(prod ? manifest : devManifest)
);
} catch (e) { } catch (e) {
console.error('Failed to rename file:', e); console.error("Failed to rename file:", e);
} }
}); });
}, },
}, },
{ {
name: 'rename-plugin', name: "rename-plugin",
setup(build) { setup(build) {
build.onEnd(async () => { build.onEnd(async () => {
try { try {
await fs.rename(path.resolve(outDir, 'main.css'), path.resolve(outDir, 'styles.css')); console.log("Renaming main.css to styles.css");
fs.renameSync(
path.resolve(outDir, "main.css"),
path.resolve(outDir, "styles.css")
);
} catch (e) { } catch (e) {
console.error('Failed to rename file:', e); console.error("Failed to rename file:", e);
} }
}); });
}, },
} },
], ],
external: [ external: [
"obsidian", "obsidian",
@ -93,7 +111,7 @@ const context = await esbuild.context({
sourcemap: prod ? false : "inline", sourcemap: prod ? false : "inline",
treeShaking: true, treeShaking: true,
outdir: outDir, outdir: outDir,
minify: prod minify: prod,
}); });
if (prod) { if (prod) {

View File

@ -1,7 +1,7 @@
{ {
"name": "obsidian-sample-plugin", "name": "obsidian-sample-plugin",
"version": "1.0.0", "version": "1.0.0",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)", "description": "Simplifies tracking your reading progress and managing your book collection in Obsidian.",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"dev": "node esbuild.config.mjs", "dev": "node esbuild.config.mjs",

View File

@ -168,6 +168,7 @@
</table> </table>
</div> </div>
<!-- svelte-ignore css_unused_selector -->
<style lang="scss"> <style lang="scss">
@use "../styles/utils"; @use "../styles/utils";

View File

@ -45,6 +45,7 @@
</form> </form>
</div> </div>
<!-- svelte-ignore css_unused_selector -->
<style lang="scss"> <style lang="scss">
@use "../styles/utils"; @use "../styles/utils";