70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
import builtins from "npm:builtin-modules";
|
|
import { build } from "npm:vite";
|
|
import deno from "npm:@deno/vite-plugin";
|
|
import banner from "npm:vite-plugin-banner";
|
|
import { resolve } from "jsr:@std/path";
|
|
import { wait } from "jsr:@denosaurs/wait";
|
|
|
|
interface BuildArgs {
|
|
production?: boolean;
|
|
watch?: boolean;
|
|
pluginDir?: string;
|
|
}
|
|
|
|
const bannerContent = `/*
|
|
* THIS IS A GENERATED/BUNDLED FILE BY VITE
|
|
* if you want to view the source, please visit the github repository of this plugin
|
|
*/
|
|
`;
|
|
|
|
export async function buildPlugin(args: BuildArgs) {
|
|
const spinner = wait("Building plugin TypeScript").start();
|
|
const cwd = args.pluginDir ? resolve(Deno.cwd(), args.pluginDir) : Deno.cwd();
|
|
|
|
await build({
|
|
root: cwd,
|
|
plugins: [deno(), banner(bannerContent)],
|
|
logLevel: "error",
|
|
build: {
|
|
watch: args.watch ? {} : undefined,
|
|
lib: {
|
|
entry: resolve(cwd, "main.ts"),
|
|
name: "main",
|
|
fileName: () => "main.js",
|
|
formats: ["cjs"],
|
|
},
|
|
minify: args.production || false,
|
|
sourcemap: args.production ? "inline" : false,
|
|
cssCodeSplit: false,
|
|
emptyOutDir: false,
|
|
outDir: ".",
|
|
rollupOptions: {
|
|
input: {
|
|
main: resolve(cwd, "main.ts"),
|
|
},
|
|
output: {
|
|
entryFileNames: "main.js",
|
|
assetFileNames: "styles.css",
|
|
},
|
|
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",
|
|
...builtins,
|
|
],
|
|
},
|
|
},
|
|
});
|
|
|
|
spinner.succeed("Build successful");
|
|
}
|