This repository has been archived by the owner on Nov 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathesbuild.js
66 lines (62 loc) · 1.6 KB
/
esbuild.js
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
const { build } = require("esbuild");
const { lessLoader } = require("esbuild-plugin-less");
const banner = `/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source visit the plugins github repository
*/
`;
const fs = require("fs");
const renamePlugin = {
name: "rename-styles",
setup: (build) => {
build.onEnd(() => {
const { outfile } = build.initialOptions;
const outcss = outfile.replace(/\.js$/, ".css");
const fixcss = outfile.replace(/main\.js$/, "styles.css");
if (fs.existsSync(outcss)) {
// console.log("Renaming", outcss, "to", fixcss);
fs.renameSync(outcss, fixcss);
}
});
},
};
const copyManifest = {
name: "copy-manifest",
setup: (build) => {
build.onEnd(() => {
fs.copyFileSync("manifest.json", "build/manifest.json");
});
},
};
const isProd = process.env.BUILD === "production";
(async () => {
try {
await build({
entryPoints: ["src/mn-main.ts"],
bundle: true,
watch: !isProd,
platform: "browser",
external: ["obsidian", "electron"],
format: "cjs",
mainFields: ["browser", "module", "main"],
banner: { js: banner },
loader: { ".svg": "text" },
sourcemap: isProd ? false : "inline",
minify: isProd,
define: {
"process.env.NODE_ENV": JSON.stringify(process.env.BUILD),
},
outfile: "build/main.js",
plugins: [
lessLoader({
javascriptEnabled: true,
}),
renamePlugin,
copyManifest,
],
});
} catch (err) {
console.error(err);
process.exit(1);
}
})();