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 dotenv from "dotenv";
import dotenvExpand from "dotenv-expand";
import manifest from "./manifest.json" with { type: "json" };
import fs from "fs/promises";
import fs from "fs";
import path from "path";
import { execSync } from "child_process";
const manifest = JSON.parse(fs.readFileSync("manifest.json", "utf8"));
const env = dotenv.config();
dotenvExpand.expand(env);
@ -35,6 +37,14 @@ if (outDir[0] === "~") {
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({
banner: {
js: banner,
@ -47,29 +57,37 @@ const context = await esbuild.context({
compilerOptions: { dev: !prod },
}),
{
name: 'copy-plugin',
name: "copy-plugin",
setup(build) {
build.onEnd(async () => {
build.onEnd(() => {
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) {
console.error('Failed to rename file:', e);
console.error("Failed to rename file:", e);
}
});
},
},
{
name: 'rename-plugin',
name: "rename-plugin",
setup(build) {
build.onEnd(async () => {
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) {
console.error('Failed to rename file:', e);
console.error("Failed to rename file:", e);
}
});
},
}
},
],
external: [
"obsidian",
@ -93,7 +111,7 @@ const context = await esbuild.context({
sourcemap: prod ? false : "inline",
treeShaking: true,
outdir: outDir,
minify: prod
minify: prod,
});
if (prod) {

View File

@ -1,7 +1,7 @@
{
"name": "obsidian-sample-plugin",
"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",
"scripts": {
"dev": "node esbuild.config.mjs",

View File

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

View File

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