generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
10 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,27 @@ | ||
import path from "node:path"; | ||
import process from "node:process"; | ||
import { fileURLToPath } from "node:url"; | ||
import builtins from "builtin-modules"; | ||
import esbuild from "esbuild"; | ||
import { context } from "esbuild"; | ||
|
||
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 isProduction = process.argv[2] === "production"; | ||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
||
const context = await esbuild.context({ | ||
banner: { | ||
js: banner, | ||
}, | ||
const ctx = await context({ | ||
entryPoints: [path.resolve(__dirname, "../src/main.ts")], | ||
minify: isProduction, | ||
bundle: true, | ||
external: ["obsidian", "@electron/remote", ...builtins], | ||
external: ["obsidian", "@electron/remote"], | ||
format: "cjs", | ||
target: "es2018", | ||
target: "es6", | ||
logLevel: "info", | ||
sourcemap: prod ? false : "inline", | ||
sourcemap: isProduction ? false : "inline", | ||
treeShaking: true, | ||
outfile: path.resolve(__dirname, "../main.js"), | ||
}); | ||
|
||
if (prod) { | ||
await context.rebuild(); | ||
if (isProduction) { | ||
await ctx.rebuild(); | ||
process.exit(0); | ||
} else { | ||
await context.watch(); | ||
await ctx.watch(); | ||
} |