-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.config.js
executable file
·54 lines (49 loc) · 1.41 KB
/
esbuild.config.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
import * as esbuild from "esbuild";
import { cpSync, readFileSync, rmSync, writeFileSync } from "fs";
const sourceFolder = "./src";
const buildFolder = "./build/prod";
const filesToCopy = ["yarn.lock", "prisma/schema.prisma", "prisma/migrations"];
const cleanBuildFolder = () => ({
name: "clean-build-folder",
setup(build) {
build.onStart(() => {
rmSync(buildFolder, { recursive: true, force: true });
});
},
});
const copyFiles = () => ({
name: "copy-files",
setup(build) {
build.onEnd(() => {
for (const file of filesToCopy) {
try {
cpSync(`./${file}`, `${buildFolder}/${file}`, { recursive: true });
} catch (e) {
console.error("Failed to copy file:", e);
}
}
});
},
});
const copyProdPackageJSON = () => ({
name: "copy-prod-package-json",
setup(build) {
build.onEnd(() => {
const packageJson = JSON.parse(readFileSync("package.json"));
delete packageJson.devDependencies;
packageJson.main = "index.cjs";
writeFileSync(`${buildFolder}/package.json`, JSON.stringify(packageJson));
});
},
});
await esbuild.build({
entryPoints: [`${sourceFolder}/index.ts`],
bundle: true,
minifyIdentifiers: false,
minifySyntax: true,
minifyWhitespace: true,
platform: "node",
packages: "external",
outfile: `${buildFolder}/index.cjs`,
plugins: [cleanBuildFolder(), copyFiles(), copyProdPackageJSON()],
});