-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrollup.config.ts
73 lines (64 loc) · 1.89 KB
/
rollup.config.ts
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
import { defineConfig } from "rollup";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { visualizer } from "rollup-plugin-visualizer";
import analyze from "rollup-plugin-analyzer";
import commonjs from "@rollup/plugin-commonjs";
import esbuild from "rollup-plugin-esbuild";
import json from "@rollup/plugin-json";
import replace from "@rollup/plugin-replace";
const isProduction = process.env["NODE_ENV"] === "production";
const HOME = process.env["HOME"];
export default defineConfig({
plugins: [
// Prisma injects the home directory. Remove that:
HOME !== undefined
? replace({
values: {
[HOME]: "~",
},
delimiters: ["", ""],
preventAssignment: true,
})
: null,
// Transpile source
esbuild({
tsconfig: "./tsconfig.prod.json",
sourceMap: !isProduction,
minify: isProduction,
}), // translate TypeScript to JS
commonjs({ extensions: [".js", ".ts"] }), // translate CommonJS to ESM
json(), // translate JSON
// Find external dependencies
nodeResolve({
exportConditions: ["node"],
preferBuiltins: true,
}),
// Statistics
analyze({ filter: () => false }), // only top-level summary
visualizer(),
],
onwarn(warning, defaultHandler) {
// Ignore "Use of eval is strongly discouraged" warnings from
// prisma. Their `eval` calls are fairly tame, though this should
// be audited with each update.
const evalWhitelist = ["@prisma/client"];
if (warning.code === "EVAL" && evalWhitelist.some(e => warning.loc?.file?.includes(e))) return;
defaultHandler(warning);
},
external: [
// Circular, uses eval, unexpeted token in plugin-commonjs
"discord.js",
// Circular
"winston-transport",
"winston",
// Relies on __dirname
"@prisma/client",
],
input: "src/main.ts",
output: {
file: "dist/server.js",
format: "module",
inlineDynamicImports: true,
sourcemap: isProduction ? undefined : "inline",
},
});