2024-03-07 20:11:39 -05:00
|
|
|
import esbuild from "esbuild";
|
|
|
|
import process from "process";
|
|
|
|
import builtins from "builtin-modules";
|
2024-07-22 20:13:14 -04:00
|
|
|
import { TsconfigPathsPlugin } from "@esbuild-plugins/tsconfig-paths";
|
2024-03-07 20:11:39 -05:00
|
|
|
import inlineWorkerPlugin from "esbuild-plugin-inline-worker";
|
2024-07-22 20:13:14 -04:00
|
|
|
import inlineImportPlugin from "esbuild-plugin-inline-import";
|
2024-03-07 20:11:39 -05:00
|
|
|
import fs from "fs";
|
2024-07-22 20:13:14 -04:00
|
|
|
const external = [
|
|
|
|
"obsidian",
|
|
|
|
"electron",
|
|
|
|
"@codemirror/autocomplete",
|
|
|
|
"@codemirror/collab",
|
|
|
|
"@codemirror/commands",
|
|
|
|
"@codemirror/language",
|
|
|
|
"@codemirror/lint",
|
|
|
|
"@codemirror/search",
|
|
|
|
"@codemirror/state",
|
|
|
|
"@codemirror/view",
|
|
|
|
"@lezer/common",
|
|
|
|
"@lezer/highlight",
|
|
|
|
"@lezer/lr",
|
|
|
|
"pdfjs-dist",
|
|
|
|
"path",
|
|
|
|
"url",
|
|
|
|
"electron",
|
|
|
|
...builtins,
|
|
|
|
];
|
2024-03-07 20:11:39 -05:00
|
|
|
async function build(prod) {
|
|
|
|
fs.mkdirSync("build/plugin", { recursive: true });
|
|
|
|
|
|
|
|
const result = await esbuild
|
|
|
|
.build({
|
|
|
|
plugins: [
|
2024-07-22 20:13:14 -04:00
|
|
|
TsconfigPathsPlugin({}),
|
|
|
|
inlineImportPlugin(),
|
2024-03-07 20:11:39 -05:00
|
|
|
inlineWorkerPlugin({
|
2024-07-22 20:13:14 -04:00
|
|
|
plugins: [TsconfigPathsPlugin({}), inlineImportPlugin()],
|
|
|
|
external,
|
2024-03-07 20:11:39 -05:00
|
|
|
target: "es2020",
|
|
|
|
format: "cjs",
|
2024-07-21 20:23:25 -04:00
|
|
|
sourcemap: prod ? false : "inline",
|
2024-07-22 20:13:14 -04:00
|
|
|
banner: {
|
|
|
|
js: "",
|
|
|
|
},
|
|
|
|
define: {
|
|
|
|
"import.meta.url": "globalThis.__importMetaUrl",
|
|
|
|
},
|
2024-03-07 20:11:39 -05:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
entryPoints: ["src/main.ts"],
|
|
|
|
bundle: true,
|
2024-07-22 20:13:14 -04:00
|
|
|
external,
|
2024-03-07 20:11:39 -05:00
|
|
|
format: "cjs",
|
|
|
|
target: "es2020",
|
|
|
|
logLevel: "info",
|
|
|
|
sourcemap: prod ? false : "inline",
|
|
|
|
treeShaking: true,
|
2024-07-22 20:13:14 -04:00
|
|
|
outfile: "build/plugin/main.js",
|
2024-03-07 20:11:39 -05:00
|
|
|
})
|
|
|
|
.catch(() => process.exit(1));
|
|
|
|
|
|
|
|
// Copy the manifest and styles.
|
|
|
|
fs.copyFileSync("manifest.json", "build/plugin/manifest.json");
|
|
|
|
fs.copyFileSync("src/styles.css", "build/plugin/styles.css");
|
|
|
|
fs.copyFileSync(
|
2024-07-22 20:13:14 -04:00
|
|
|
"node_modules/@btfash/sqlite-wasm/sqlite-wasm/jswasm/sqlite3.wasm",
|
2024-03-07 20:11:39 -05:00
|
|
|
"build/plugin/sqlite3.wasm"
|
|
|
|
);
|
2024-07-22 20:13:14 -04:00
|
|
|
// fs.writeFileSync("build/meta.json", JSON.stringify(result.metafile));
|
2024-03-07 20:11:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run the build.
|
|
|
|
build(process.argv[2] === "production");
|