forked from dikidjatar/acode-plugin-version-control-gitpro
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
75 lines (66 loc) · 1.9 KB
/
Copy pathesbuild.config.mjs
File metadata and controls
75 lines (66 loc) · 1.9 KB
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
69
70
71
72
73
74
75
import { exec } from "child_process";
import * as esbuild from "esbuild";
import { sassPlugin } from "esbuild-sass-plugin";
const isServe = process.argv.includes("--serve");
// Function to pack the ZIP file
function packZip() {
exec("node ./pack-zip.js", (err, stdout, stderr) => {
if (err) {
console.error("Error packing zip:", err);
return;
}
console.log(stdout.trim());
});
}
// Custom plugin to pack ZIP after build or rebuild
const zipPlugin = {
name: "zip-plugin",
setup(build) {
build.onEnd(() => {
packZip();
});
},
};
// Custom plugin to redirect CodeMirror dependencies to Acode's global acode.require system
const codemirrorExternalPlugin = {
name: "codemirror-external",
setup(build) {
build.onResolve({ filter: /^@codemirror\/(state|view|language|autocomplete|commands|lint|search)$|^codemirror$/ }, (args) => {
return { path: args.path, namespace: "codemirror-external" };
});
build.onLoad({ filter: /.*/, namespace: "codemirror-external" }, (args) => {
return {
contents: `module.exports = acode.require('${args.path}');`,
loader: "js",
};
});
},
};
// Base build configuration
let buildConfig = {
entryPoints: ["src/main.ts"],
bundle: true,
minify: !isServe,
logLevel: "info",
color: true,
outdir: "dist",
plugins: [codemirrorExternalPlugin, zipPlugin, sassPlugin()],
resolveExtensions: ['.ts', '.d.ts']
};
// Main function to handle both serve and production builds
(async function () {
if (isServe) {
console.log("Starting development server...");
// Watch and Serve Mode
const ctx = await esbuild.context(buildConfig);
await ctx.watch();
const { host, port } = await ctx.serve({
servedir: ".",
port: 3000,
});
} else {
console.log("Building for production...");
await esbuild.build(buildConfig);
console.log("Production build complete.");
}
})();