spotube/esbuild.config.mjs
2021-06-16 13:50:13 +06:00

42 lines
1.0 KiB
JavaScript

import { build } from "esbuild";
import { mkdir, copyFile } from "fs/promises";
import { join } from "path";
build({
bundle: true,
outdir: "./dist",
minify: false,
platform: 'node',
target: "es6",
color: true,
jsx: "transform",
sourcemap: true,
tsconfig: "./tsconfig.json",
entryPoints: ["src/index.tsx"],
target: ['node12'],
loader: {
".png": "file",
".jpg": "file",
".gif": "file",
".svg": "file",
".node": "file"
},
plugins: [
{
name: "Native Addon",
setup(build) {
build.onResolve({ filter: /\.node$/ }, async (arg) => {
const pluginName = arg.path.split("/").reverse()[0]
mkdir(join(process.cwd(), "dist"), {recursive: true})
await copyFile(join(arg.resolveDir, arg.path), join(process.cwd(), "dist", pluginName))
return {
external: true,
path: "./"+pluginName,
namespace: "js",
pluginName
}
})
}
},
]
}).catch(() => process.exit(1));