generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.config.mjs
68 lines (57 loc) · 1.54 KB
/
esbuild.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as fs from "fs";
import * as path from "path";
import esbuild from "esbuild";
import { fileURLToPath } from "url";
import process from "process";
import svelte from "esbuild-svelte";
import sveltePreprocess from "svelte-preprocess";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
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.
*/
`;
function copyAssetsPlugin() {
return {
name: "copy-assets",
setup(build) {
build.onEnd(() => {
const rootDir = __dirname;
const distDir = path.join(rootDir, "dist");
// Copy manifest.json
fs.copyFileSync(
path.join(rootDir, "manifest.json"),
path.join(distDir, "manifest.json")
);
console.log("Copied manifest.json to dist/");
});
},
};
}
const prod = process.argv.includes("production");
console.log(`[esbuild] Production mode: ${prod}`);
await esbuild.build({
entryPoints: ["src/main.ts"],
outfile: "dist/main.js",
bundle: true,
external: ["obsidian"],
format: "cjs",
target: "es2018",
logLevel: "info",
// Turn off source maps
sourcemap: false,
minify: prod,
banner: {
js: banner,
},
plugins: [
svelte({
compilerOptions: { css: true },
preprocess: sveltePreprocess(),
}),
copyAssetsPlugin(),
],
conditions: [prod ? "production" : "development"],
});
console.log("[esbuild] Build complete, no .map files generated!");