forked from aymene69/stremio-jackett
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.js
59 lines (52 loc) · 1.42 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
import { build } from "esbuild";
import { readFileSync, rmSync } from "fs";
const { devDependencies } = JSON.parse(readFileSync("./package.json", "utf8"));
const start = Date.now();
try {
const outdir = "dist/addon";
rmSync(outdir, { recursive: true, force: true });
build({
bundle: true,
entryPoints: [
"./src/index.js",
"./src/**/*.css",
"./src/**/*.hbs",
// "./src/**/*.html"
],
external: [...(devDependencies && Object.keys(devDependencies)), "better-sqlite3"],
keepNames: true,
loader: {
".css": "copy",
".hbs": "copy",
".html": "copy",
},
minify: true,
outbase: "./src",
outdir,
outExtension: {
".js": ".cjs",
},
platform: "node",
plugins: [
{
name: "populate-import-meta",
setup: ({ onLoad }) => {
onLoad({ filter: new RegExp(`${import.meta.dirname}/src/.*\.(js|ts)$`) }, args => {
const contents = readFileSync(args.path, "utf8");
const transformedContents = contents
.replace(/import\.meta/g, `{dirname:__dirname,filename:__filename}`)
.replace(/import\.meta\.filename/g, "__filename")
.replace(/import\.meta\.dirname/g, "__dirname");
return { contents: transformedContents, loader: "default" };
});
},
},
],
}).then(() => {
// biome-ignore lint/style/useTemplate: <explanation>
console.log("⚡ " + "\x1b[32m" + `Done in ${Date.now() - start}ms`);
});
} catch (e) {
console.log(e);
process.exit(1);
}