remotely-save/esbuild.config.mjs

72 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-11-27 06:45:46 +00:00
import esbuild from "esbuild";
2024-03-24 16:21:56 +00:00
import inlineWorkerPlugin from "esbuild-plugin-inline-worker";
2024-05-07 16:20:15 +00:00
import process from "process";
2021-11-27 06:45:46 +00:00
// import builtins from 'builtin-modules'
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
*/
`;
2022-01-08 06:43:53 +00:00
console.log(`esbuild version = ${esbuild.version}`);
2021-11-27 06:45:46 +00:00
const prod = process.argv[2] === "production";
2021-11-28 17:03:17 +00:00
const DEFAULT_DROPBOX_APP_KEY = process.env.DROPBOX_APP_KEY || "";
2021-12-28 16:35:46 +00:00
const DEFAULT_ONEDRIVE_CLIENT_ID = process.env.ONEDRIVE_CLIENT_ID || "";
const DEFAULT_ONEDRIVE_AUTHORITY = process.env.ONEDRIVE_AUTHORITY || "";
2021-11-28 17:03:17 +00:00
2021-11-27 06:45:46 +00:00
esbuild
2023-12-17 07:18:23 +00:00
.context({
2021-11-27 06:45:46 +00:00
banner: {
js: banner,
},
2021-12-11 14:45:21 +00:00
loader: {
".svg": "text",
},
2021-11-27 06:45:46 +00:00
entryPoints: ["./src/main.ts"],
bundle: true,
external: [
"obsidian",
"electron",
"fs",
2022-02-12 04:28:47 +00:00
"tls",
"net",
2023-12-17 07:18:23 +00:00
"http",
"https",
2024-04-26 18:27:24 +00:00
"vm",
2021-11-27 06:45:46 +00:00
// ...builtins
],
2022-04-30 03:59:18 +00:00
inject: ["./esbuild.injecthelper.mjs"],
2021-11-27 06:45:46 +00:00
format: "cjs",
2023-12-17 07:18:23 +00:00
// watch: !prod, // no longer valid in esbuild 0.17
2021-11-27 06:45:46 +00:00
target: "es2016",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
minify: prod,
outfile: "main.js",
2021-11-28 17:03:17 +00:00
define: {
"process.env.DEFAULT_DROPBOX_APP_KEY": `"${DEFAULT_DROPBOX_APP_KEY}"`,
2021-12-28 16:35:46 +00:00
"process.env.DEFAULT_ONEDRIVE_CLIENT_ID": `"${DEFAULT_ONEDRIVE_CLIENT_ID}"`,
"process.env.DEFAULT_ONEDRIVE_AUTHORITY": `"${DEFAULT_ONEDRIVE_AUTHORITY}"`,
2022-04-30 03:59:18 +00:00
global: "window",
"process.env.NODE_DEBUG": `undefined`, // ugly fix
"process.env.DEBUG": `undefined`, // ugly fix
2021-11-28 17:03:17 +00:00
},
2024-03-24 16:21:56 +00:00
plugins: [inlineWorkerPlugin()],
2021-11-27 06:45:46 +00:00
})
2023-12-17 07:18:23 +00:00
.then((context) => {
if (process.argv.includes("--watch")) {
// Enable watch mode
context.watch();
} else {
// Build once and exit if not in watch mode
context.rebuild().then((result) => {
context.dispose();
});
}
})
2021-11-27 06:45:46 +00:00
.catch(() => process.exit(1));