This commit is contained in:
Andras Schmelczer 2024-12-18 22:38:51 +00:00
commit 58859f52e5
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C

View file

@ -5,12 +5,6 @@ import path from "node:path";
import fs from "node:fs"; import fs from "node:fs";
import { wasmPack } from "esbuild-plugin-wasm-pack"; import { wasmPack } from "esbuild-plugin-wasm-pack";
const banner = `/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;
const prod = process.argv[2] === "production"; const prod = process.argv[2] === "production";
async function copyFiles(sourceDir, destinationDir) { async function copyFiles(sourceDir, destinationDir) {
@ -76,9 +70,6 @@ let wasmPlugin = {
}, },
}; };
const context = await esbuild.context({ const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ["src/plugin.ts"], entryPoints: ["src/plugin.ts"],
bundle: true, bundle: true,
external: [ external: [
@ -106,7 +97,9 @@ const context = await esbuild.context({
minify: prod, minify: prod,
plugins: [ plugins: [
wasmPlugin, wasmPlugin,
wasmPack({ prod
? null
: wasmPack({
target: "web", target: "web",
path: "../backend/sync_lib", path: "../backend/sync_lib",
}), }),
@ -114,6 +107,10 @@ const context = await esbuild.context({
name: "post-compile", name: "post-compile",
setup(build) { setup(build) {
build.onEnd((result) => { build.onEnd((result) => {
if (prod) {
return;
}
if (result.errors.length === 0) { if (result.errors.length === 0) {
copyFiles( copyFiles(
["manifest.json", "versions.json", ".hotreload"], ["manifest.json", "versions.json", ".hotreload"],
@ -124,11 +121,21 @@ const context = await esbuild.context({
"build", "build",
"/mnt/c/Users/Andras/Desktop/test/test/.obsidian/plugins/my-plugin" "/mnt/c/Users/Andras/Desktop/test/test/.obsidian/plugins/my-plugin"
); );
copyFiles(
["manifest.json", "versions.json", ".hotreload"],
"/mnt/c/Users/Andras/Desktop/test/test2/.obsidian/plugins/my-plugin"
);
copyFiles(
"build",
"/mnt/c/Users/Andras/Desktop/test/test2/.obsidian/plugins/my-plugin"
);
} }
}); });
}, },
}, },
], ].filter(Boolean),
}); });
if (prod) { if (prod) {